I'm not quite sure what exactly it is that I'm doing wrong here. What I want is if someone type in [ php] $blah; [ /php] I want PHP to find it and colorize it. So far I've gotten this and it works just fine on my older machine, but now it doesn't.
function phpcode($code) {
global $result;
$result[$code]=stripslashes($result[$code]);
$result[$code]=htmlentities($result[$code]);
$result[$code]=str_replace("&", "&", $result[$code]);
$result[$code]=str_replace("<", "<", $result[$code]);
$result[$code]=str_replace(">", ">", $result[$code]);
$result[$code]=str_replace(""", "\"", $result[$code]);
@ob_start();
@highlight_string($result[$code]);
$result[$code]=@ob_get_contents();
@ob_end_clean();
$result[$code] = "<table width='100%' cellspacing='0' cellpadding='0' align='center'><tr><td><b>PHP Code:</b><br>".$result[$code]."</td></tr></table>";
return $result[$code];
}
Then I use this expression to find it within the text:
$text=preg_replace("/\[php\]((.|\n)*?)\[\/php\]/ise", "phpcode('\\1')", $text);
$text being the code I want colorized. Anyone help me with this? Dunno what I did wrong here. 🙁