geshi高亮类高亮[code]中文本例子
$高亮前的文本 = '以下是一段php代码:
<?php
$a = $b;
$b = $c;
$c = $d;
$d = $e;
完了';
$高亮后的文本 = preg_replace_callback('/[code(?:=(.*))?](.*)[/code]/isU', '代码高亮函数', $高亮前的文本);
function 代码高亮函数($arr) {
$type = trim($arr[1]);
if ($type == '') {
$type = 'php';
}
$code = trim($arr[2]);
require_once 'class/geshi/geshi.php';
$geshi = new geshi($code, $type);
$geshi->set_header_type(GESHI_HEADER_DIV);
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$html = $geshi->parse_code();
return $html;
}
geshi源代码:http://sourceforge.net/projects/geshi/
阅:2407 |
发表于2015-07-08 12:21 |
#其他教程