function php_code($text){
$php_start_html = "<table border=0 align=center width=95%><tr><td><font size=-1>"._PHPCODE."</font></td></tr></table><table border=0 align=center width=95% border=0 cellspacing=1 cellpadding=0 bgcolor=$bgcolor2><tr><td><table border=0 align=center width=100% cellspacing=4 bgcolor=#FFFFFF><tr><td><font class=\"php\">";
$php_end_html = "</font></td></tr></table></td></tr></table>";
$matches = array();
$match_count = preg_match_all("#\[php\](.*?)\[/php\]#si", $text, $matches);
for ($i = 0; $i < $match_count; $i++)
{
$before_replace = $matches[1][$i];
$after_replace = trim($matches[1][$i]);
$str_to_match = "
Codice PHP:
" . $before_replace . "
";
$replacement = $php_start_html;
$after_replace = str_replace('<', '<', $after_replace);
$after_replace = str_replace('>', '>', $after_replace);
$after_replace = str_replace('&', '&', $after_replace);
$added = FALSE;
if (preg_match('/^<\?.*?\?>$/si', $after_replace) <= 0)
{
$after_replace = "<?php $after_replace ?>";
$added = TRUE;
}
if(strcmp('4.2.0', phpversion()) > 0)
{
ob_start();
highlight_string($after_replace);
$after_replace = ob_get_contents();
ob_end_clean();
}
else
{
$after_replace = highlight_string($after_replace, TRUE);
}
if ($added == TRUE)
{
$after_replace = str_replace('<font color="#0000BB"><?php ', '<font color="#0000BB">', $after_replace);
$after_replace = str_replace('<font color="#0000BB">?></font>', '', $after_replace);
}
$after_replace = preg_replace('/<font color="(.*?)">/si', '<span style="color: \\1;">', $after_replace);
$after_replace = str_replace('</font>', '</span>', $after_replace);
$after_replace = str_replace("\n", '', $after_replace);
$replacement .= $after_replace;
$replacement .= $php_end_html;
$text = str_replace($str_to_match, $replacement, $text);
}
$text = str_replace("
Codice PHP:
", $php_start_html, $text);
$text = str_replace("
", $php_end_html, $text);
return $text;
}