• 3619阅读
  • 0回复

php代码高亮显示函数 [复制链接]

上一主题 下一主题
离线cai
 

只看楼主 倒序阅读 0楼 发表于: 2006-04-11
  1. function phphighlite($code)
  2. {
  3.    $code = str_replace('[PHP]', '<'.'?', $code);
  4.    $code = str_replace('[/PHP]', '?'.'>', $code);
  5.    if(!strpos($code,"<?\n") && !strpos($code,'<?') && substr($code,0,2) != '<?')
  6.    {
  7.        $code = '<'.'?'.trim($code).' ?'.'>';
  8.        $addedtags = 1;
  9.    }
  10.    ob_start();
  11.    $oldlevel = error_reporting(0);
  12.    highlight_string($code);
  13.    error_reporting($oldlevel);
  14.    $buffer = ob_get_contents();
  15.    ob_end_clean();
  16.    if ($addedtags)
  17.    {
  18.        $openingpos = strpos($buffer, '<?');
  19.        $closingpos = strrpos($buffer, '?');
  20.        $buffer = substr($buffer, 0, $openingpos).substr($buffer, $openingpos+5, $closingpos-($openingpos+5)).substr($buffer, $closingpos+5);
  21.    }
  22.    $buffer = str_replace('"', "\"", $buffer);
  23.    $buffer = str_replace('<br />', '', $buffer);
  24.    return $buffer;
  25. }
grant all privileges on *.* to 'a'@'localhost' identified by 'a' with grant option;flush privileges;
快速回复
限100 字节
 
上一个 下一个