View Full Version : Coloring code.

01-01-2008, 08:45 AM
Basically what I want to accomplish is this:


if (isset($_POST['input']) {
$string = str_replace('word1', 'word2', $string);
echo $string . "word3";
} else {
exit("this is text");

Yes, that is just random PHP. What I basically want to accomplish is what the
tag on CF (and all other vBulletin forums) does, color the different parts of the code to make it easier to understand. I want to do it for HTML though (not PHP). I assume it's done with many <span style="color:#xxxxxx"></span> tags around the string to color the text. The only way I can even imagine doing this is with several complicated and confusing str_replace() and array() tags. I know there's probably an easier technique, or at least I hope there is. Any help would be appreciated. Thanks.

01-01-2008, 10:02 AM
vB(and pretty much everyone) uses highlight_string() (http://php.net/highlight_string)/highlight_file() (http://php.net/highlight_file). In the manual you can also find the color settings that you can change with ini_set() (http://php.net/ini_set)

01-01-2008, 10:26 AM
Good to know. I'm pretty sure those only work for PHP code though? I want to do it for HTML and CSS. If worse comes to worse, I'll just do it manually with styled tags <var>, <em>, <strong>, etc.. Like:

<var>#tagid a:hover</var> <em>{</em> color:<strong>#000000</strong>; <em>}</em>

#tagid a:hover { color:#000000; }

It's take way more time to accomplish, but if it the only way, I'll manage. Just want to clarify whether or not there's a simpler PHP alternative first.

01-01-2008, 06:02 PM
GeShi (http://geshi.org)