views:

151

answers:

5

How do you display your php source code with highlight or view source or is there more alternatives to this?

+5  A: 

PHP has two native functions that might be of interest: highlight_file() and highlight_string(). If neither of those are ideal, you could also use Google Code Prettify to achieve this result. This is the solution many use, including StackOverflow itself.

Alternatives:

Jonathan Sampson
+1  A: 

On many servers if you give it a .phps file extension the source code will be displayed and highlighted.

John Conde
What kicks this into gear?
alex
+2  A: 

You can use the php highlight_file function to echo the source of a file with syntax highlighting.

tj111
+1 for native function
Gordon
A: 

GeSHi - Generic Syntax Highlighter is another opensource javascript library.

Yada
A: 

I do my editing in gvim which can be configured to do syntax sensitive code highlighting (amongst other things).

PHP has a builtin function which converts a string to coloured HTML

http://php.net/manual/en/function.highlight-string.php

so...

<?php

print highlight_string(file_get_contents(__FILE__));

?>

demonstrates this.

You might also wnat to have a lokk at GeSHi

http://qbnz.com/highlighter/

HTH

C.

symcbean