//------- 添加 [runcode] Html代码 [/runcode] 来运行Html代码
function runcodedisp($code) {
global $discuzcodes;
$discuzcodes['pcodecount']++;
$code = htmlspecialchars(str_replace('\\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "\\1", $code)));
$discuzcodes['codehtml'][$discuzcodes['pcodecount']] = "
提示:您可以先修改部分代码再运行
";
$discuzcodes['codecount']++;
return "[\tDISCUZ_CODE_$discuzcodes[pcodecount]\t]";
}
//------- 添加 [php] php代码 [/php] 来高亮显示php代码,进行php语法着色
function phpcodedisp($code) {
global $discuzcodes;
$discuzcodes['pcodecount']++;
$code = phphighlite(str_replace("\\\"", "\"", $code));
$discuzcodes['codehtml'][$discuzcodes['pcodecount']] = "
$code
";
$discuzcodes['codecount']++;
return "[tDISCUZ_CODE_$discuzcodes[pcodecount]t]";
}
function phphighlite($code) {
if(!strpos($ code," $code = '<'。 '?'.trim($code).' ?'.'>';
$addedtags = 1;
ob_start();
ハイライト_文字列($code);
error_reporting($oldlevel);
$buffer = ob_get_contents( );
ob_end_clean();
if ($addedtags) {
$openingpos = strpos($buffer, '');
$closepos = strrpos($buffer, '?');
$buffer = substr( $buffer, 0, $openingpos).substr($buffer, $openingpos+5, $finishingpos-($openingpos+5)).substr($buffer, $closeingpos+5);
}
$buffer = str_replace(' "', """, $buffer);
$buffer = str_replace('
', '', $buffer);
return $buffer;
//------结束
3.继续修正include/discuzcode.func.php
查找
$message = preg_replace("/s*[runcode](.+?)[/runcode]s*/ies","runcodedisp('\1')", $message);