PHP’s function Code Highlighting
Just recently i discovered something very usefull. It could be very helpfull in any website or forum regarding programming.
There is a function in PHP called Code Highlighting. This would result in a very easy way of displaying php code onto a website. Just let me give an example.
<?php highlight_string('<?php echo "test"; ?>'); ?>
This outputted this in the displayed HTML:
<span style=”color: rgb(0, 0, 187);”><?php </span><span style=”color: rgb(0, 119, 0);”>echo </span><span style=”color: rgb(221, 0, 0);”>”test”</span><span style=”color: rgb(0, 119, 0);”>; </span><span style=”color: rgb(0, 0, 187);”>?></span>
</span>
Which looks just like this:
<?php echo “test”; ?>
As you can see, this can be very helpful.
Of course you need to be careful with this function as soon as you use it in “public”. You need to make sure you escape every quotes in the string with addslashes. This will prevent anything from happening.
Of course i can’t guarantee 100% protection. That’s pretty tricky. Good luck!
PS: http://nl2.php.net/manual/en/function.highlight-file.php
