NYCPHP Meetup

NYPHP.org

[nycphp-talk] Code Highlighting a Mixed Content (HTML/PHP) File

David Sklar sklar at sklar.com
Wed Sep 22 16:30:11 EDT 2004


invisiblemute wrote:
> ...</lurk>
> 
> Did quite a bit of searching and found lots of scripts on sites all 
> around the world to syntax highlight PHP code. What I didn't seem to 
> find was how to do it elegantly with a file of mixed content types 
> without preg_matching, preg_replacing, etc. I thought I could do it with 
> two built in PHP functions but the following fails and doesn't return 
> anything:
> 
> <?php
> html_entity_decode(highlight_file("some_directory/$file[name]"));
> ?>
> 
> Leaving out the html_entity_decode() it reads in the file but runs an 
> html_entities() on it which I don't want.
> 
> Thanks.
> 
> </lurk>...

highlight_file() only returns the HTML with the highlighted stuff if you 
pass it a second argument of "true" (Otherwise, it just prints it). Try:

print html_entity_decode(highlight_file("$dir/$file", true));

David



More information about the talk mailing list