Improved PHP syntax highlighting
Posted 5 April 2004
PHP_Highlight uses PHP’s built in tokenizer to provide reliable syntax highlighting for PHP code when server-side highlighting is required.
This will generates valid XHTML output, with function referencing (links back to the PHP manual for PHP functions) and configurable line numbering.
Extendable output methods provide loads of flexibility:
toHtml()
outputs highlighted PHP, lines ending with a
toHtmlBlock()
was designed for highlighting PHP code in user comments. Text is unaffected, but PHP code is wrapped and styled.
toList()
outputs highlighted PHP in an orderedlist.
toArray()
outputs the highlighted PHP as an array, allowing for further customisation.
Highlighting can be inline (with styles), or the same as highlight_file() where colors are taken from php.ini.
Usage is very easy, for example:
This will output the contents of the current file with syntax highlighting and function referencing in the three different output formats.