Hey, when I use the tags [ php ] [ /php ], your script is coded in nice colors, what's the trick to do this??
| SitePoint Sponsor |
Hey, when I use the tags [ php ] [ /php ], your script is coded in nice colors, what's the trick to do this??




My code always comes out in colour when I put them between php tags.
PHP Code:<?php
echo "Hello";
?>PHP Code:echo "Hello";
No, that's not my question, I mean when I want to display code on my site, and I want It coded in colors, how do I do that?
A syntax highlighting system is complex. It parses the language looking for syntax conventions, and placing tags around them to enable them to show up in a certain colour.
You may find pre-written code to do this for PHP, or you may need to do it yourself.
[mmj] My magic jigsaw
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Bit Depth Blog · Twitter · Contact me
Neon Javascript Framework Jokes


You might be able to find the answer by looking at the source.php file at php.net: [http://php.net/source.php?url=/source.php].





What you are after is the highlight_string() function. It will color code a string based on the colors set for source code coloring in the php.ini file. For instance let's say we pulled a bit of code from a database and stored it in a variable named $data
If we did
PHP Code://Produces color-highlighted version of $data
print highlight_string($data);
Please don't PM me with questions.
Use the forums, that is what they are here for.

Or if you want to highlight the content of a file, you can use
PHP Code:show_source("filename.php");
Bookmarks