时间:2021-07-01 10:21:17 帮助过:28人阅读
代码如下:
function copycode(obj) {
var rng = document.body.createTextRange();
rng.moveToElementText(obj);
rng.scrollIntoView();
rng.select();
rng.execCommand("Copy");
rng.collapse(false);
}
代码如下:
function runCode(obj) {
var winname = window.open('', "_blank", '');
winname.document.open('text/html', 'replace');
winname.document.writeln(obj.value);
winname.document.close();
}
function saveCode(obj) {
var winname = window.open('', '_blank', 'top=10000');
winname.document.open('text/html', 'replace');
winname.document.writeln(obj.value);
winname.document.execCommand('saveas','','code.htm');
winname.close();
}
代码如下:
$discuzcodes['codecount']++;
return "[\tDISCUZ_CODE_$discuzcodes[pcodecount]\t]";
}
代码如下:
//------- 添加 [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']] = "
/g,''); delpost.runcode$discuzcodes[codecount] .value = ffcod; 提示:您可以先修改部分代码再运行
";
$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']] = "
PHP代码如下:$code
";
$discuzcodes['codecount']++;
return "[\tDISCUZ_CODE_$discuzcodes[pcodecount]\t]";
}
function phphighlite($code) {
if(!strpos($code,"\n") && !strpos($code,'') && substr($code,0,2) != '') {
$code = '<'.'?'.trim($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;
}
//------- 结束
代码如下:
$message = preg_replace("/\s*\[code\](.+?)\[\/code\]\s*/ies", "codedisp('\\1')", $message);
代码如下:
//------- runcode
$message = preg_replace("/\s*\[runcode\](.+?)\[\/runcode\]\s*/ies", "runcodedisp('\\1')", $message);
//------- php
$message = preg_replace("/\s*\[php\](.+?)\[\/php\]\s*/ies", "phpcodedisp('\\1')", $message);
以上就介绍了discuz 7.0 推荐Discuz!5的PHP代码高亮显示与实现可运行代码,包括了discuz 7.0方面的内容,希望对PHP教程有兴趣的朋友有所帮助。