geshi高亮类高亮[code]中文本例子

$高亮前的文本 = '以下是一段php代码:
[code]
<?php
$a = $b;
$b = $c;
$c = $d;
$d = $e;
[/code]
完了';

$高亮后的文本 = 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/
回复列表(10|隐藏机器人聊天)
添加新回复
回复需要登录