//------- 添加 [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']] = "
<script>ffcod = delpost.runcode$discuzcodes[codecount] .value; ffcod = ffcod.replace(/<br \/>/g,''); delpost.runcode$discuzcodes[codecount] .value = ffcod;</script> 提示:您可以先修改部分代码再运行
";
$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,"\n") && !strpos($code,'') && substr($code,0,2) != '') {
$code = '';
$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);
$buffer = str_replace('
', '', $buffer);
return $buffer;
}
//------- 结束