Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint:
Highlight Source in Your PHP App
Apr 11, 2005 @ 11:52:37

New from SitePoint today is an article that explains how you can use various methods to highlight source code in your PHP applications.

If you run a Website about programming, chances are that you display source code on your site's pages. Wouldn't it be great if the source code was highlighted -- displayed using different colors -- in the same way the desktop programming editors and IDEs display it? This would certainly make it much easier for your visitors to read the code.

They give two methods for highlighting code - PHP's own internal highlighter (the same functionality it uses to display a .phps when it's loaded in the browser) and the PEAR Text_Highlighter package. The internal highlighter is included with every PHP distribution out there and is simple to modify (php_value settings in a .htaccess), but it does have drawbacks: the display of other languges is somewhat "iffy" and the resulting HTML isn't up to standards.

So, enter Text_Highlighter, a powerful package that is much more flexible than its internal cousin. Not only can it display PHP code correctly, but it also handles other languages (like css, sql, python, javascript - just to name a few). Add to this the fact that the highlighting options are set in the PHP script itself (no maintaining a separate file), and you've got one useful system...

tagged:

Link:


Trending Topics: