嘎嘎,从sablog-X里面挖一段函数到风色同学的O-BLOG。:heart: 用[php ] [ /php](注意中间不要空格)将php代码括起来就 可以看到高亮的php语法,很方便那些代码转贴和查看. 在function.php最后添加一段下面的代码。 PHP: // 高亮显示PHP //函数来自sablog-X 嘎嘎 function phphighlite($code) { if (floor(phpversion())<4) { $buffer = $code; } else { $code = preg_replace("/<style .*?<\/style>/is", "", $code); $code = preg_replace("/<script .*?<\/script>/is", "", $code); $code = preg_replace("/<br\s*\/?>/i", "\n", $code); $code = preg_replace("/<\/?p>/i", "\n", $code); $code = preg_replace("/<\/?td>/i", "\n", $code); $code = preg_replace("/<\/?div>/i", "\n", $code); $code = preg_replace("/<\/?blockquote>/i", "\n", $code); $code = preg_replace("/<\/?li>/i", "\n", $code); $code = strip_tags($code); $code = preg_replace("/\&\#.*?\;/i", "", $code); $code = str_replace(" ", "\t", $code); $code = str_replace(""", '"', $code); $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); if (!strpos($code,"<?") and substr($code,0,2)!="<?") { $code="<?\n".trim($code)."\n?>"; $addedtags=1; } ob_start(); $oldlevel=error_reporting(0); highlight_string($code); error_reporting($oldlevel); $buffer = ob_get_contents(); ob_end_clean(); if ($addedtags) { $openingpos = strpos($buffer,'<?'); $closingpos = strrpos($buffer, '?'); $buffer=substr($buffer, 0, $openingpos).substr($buffer, $openingpos+5, $closingpos-($openingpos+5)).substr($buffer, $closingpos+5); } $buffer = str_replace(""", "\"", $buffer); } return "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"table-layout:fixed; word-break:break-all\">\n<tr>\n<td height=\"15\"><strong>PHP代码:</strong></td>\n</tr>\n<tr>\n<td class=\"phpcode\">".$buffer."</td>\n</tr>\n</table>\n"; } 然后在build.php中,搜索 PHP: $date = $oneRe['date']; 在它上面添加: PHP: if (preg_match("/\[php\].+?\[\/php\]/is",$oneRe['content'])) { $oneRe['content'] =preg_replace("/\s*\[php\](.+?)\[\/php\]\s*/ies", "phphighlite('\\1')", $oneRe['content']); }else{ $oneRe['content'] =$oneRe['content']; }