Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > PHP: Общие вопросы > Подсветка синтаксиса PHP


Автор: Opr 19.3.2005, 12:54
Код
function PHP_syntax_highlighting($code) {
 if (floor(phpversion())<4) $output = $code;
 else {
  $code = str_replace("<br>", "", $code);
  $code = str_replace("<br />", "", $code);
  $code = str_replace(">", ">", $code);
  $code = str_replace("<", "<", $code);
  $code = str_replace("&", "&", $code);
  $code = str_replace('$', '\$', $code);
  $code = str_replace('\n', '\\\\n', $code);
  $code = str_replace('\r', '\\\\r', $code);
  $code = str_replace('\t', '\\\\t', $code);
  $code = stripslashes($code);
  if (!strpos($code, "<?") and substr($code, 0, 2) != "<?") {
   $code = "<?\n".trim($code)."\n?>";
   $newtags = TRUE;
  }
  ob_start();
  $oldlevel = error_reporting(0);
  highlight_string($code);
  error_reporting($oldlevel);
  $output = ob_get_contents();
  ob_end_clean();
  if ($newtags) {
   $openingpos = strpos($output, "<?");
   $output = substr($output, 0, $openingpos).substr($output, $openingpos+5, -50)."</font></code>";
  }
  $output = str_replace(""", "\"", $output);
 }
 return "PHP-code:<br /><br />$output";
}

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)