试试SyntaxHighlighter

之前贴代码一直用的最原始的办法,自己写了个程序把“程序代码”转换成对应的HTML代码,然后贴进来。好处就是,格式绝对不会乱掉。坏处就是没有语法高亮。现在试试SyntaxHighlighter,效果还不错。
[php]
<?php
$export_id = $_GET['export_id'];

//读取状态文件的最后一行
$file = escapeshellarg("/var/tmp/$export_id");
$line = `tail -n 1 $file`;

//解析出当前步骤数,总步骤数,和当前状态信息,并以json格式返回给client
$line = trim($line);
$a = strpos($line,'/');
$b = strpos($line,']');
$current_step = (int)substr($line,1,$a);
$total_step = (int)substr($line,$a+1,$b-$a);
$msg = substr($line,$b+1);
echo json_encode(array(
"current_step"=>$current_step,
"total_step"=>$total_step,
"msg"=>$msg
));
?>
[/php]
[c]
int main(int argc, char* argv[]){
printf("hello, world!\n");
return 0;
}
[/c]


Last modified on 2009-10-28