Salve a tutti, volevo fare in modo che in un forum postando del codice php si colorasse lo script in base alla sintassi in php come ad esempio su questo forums.
Io stò utilizzando questo codice:
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('&lt;', '<', $after_replace);
$after_replace = str_replace('&gt;', '>', $after_replace);
$after_replace = str_replace('&amp;', '&', $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">&lt;?php ', '<font color="#0000BB">', $after_replace);
$after_replace = str_replace('<font color="#0000BB">?&gt;</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;
}
mi dispiace di come viene postato il codice ma lo script va in conflitto con il vostro mod
Cmq tornando al problema in questa variabile
$after_replace = "<?php $after_replace ?>";
viene inserito il codice e viene colorato, da qui il problema in pratica viene inserito il codice ma vengono inseriti anche i tag <?php ?> e come conseguenza nel codice mi trovo due tag che non dovrebbero esserci, provando a toglierli da quella variabile il codice non viene più colorato come posso risolvere questo problema?

Vi ringrazio anticipatamente