12th January 2008 - 3 minutes read time
When printing off source code there is a handy function that will parse the code and produce nice looking syntax highlighted code. There are actually two functions you can use. The highlight_string() function takes a string as a parameter and will print the highlighted code. The highlight_file() function takes a file name as a parameter, the contents of which are printed off with highlighted syntax. For now I will concentrate on the highlight_string() function, but the output of these two functions is the same.
To use the highlight_string() function just pass it a string. The following code:
highlight_string('<?php
function checkslash($slashes_string){
if (get_magic_quotes_gpc()==1) {
return $slashes_string;
}else{
return addslashes($slashes_string);
};
};
?>');
Will produce the following output: