`
jaketseng
  • 浏览: 40493 次
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

在一行内使用highlight_string函数

 
阅读更多

This class show a code formated.
Allow options for to format.
Options: highlight code and to show line number

<?php

class
Code
{

function
printCode($code, $high_light = 0, $lines_number = 0
)
{
if (!
is_array($code)) $code = explode("/n", $code
);

$count_lines = count($code
);

foreach (
$code as $line => $code_line
) {

if (
$lines_number) $r1 = "<span class=/"lines_number/">".($line + 1)." </span>"
;

if (
$high_light
) {
if (
ereg("</?(php)?[^[:graph:]]", $code_line
)) {
$r2 = highlight_string($code_line, 1)."<br />"
;
} else {

$r2 = ereg_replace("(&lt;/?php&nbsp;)+", "", highlight_string("<?php ".$code_line, 1))."<br />"
;

}
} else {
$r2 = (!$line) ? "<pre>" : ""
;
$r2 .= htmlentities($code_line
);
$r2 .= ($line == ($count_lines - 1)) ? "<br /></pre>" : ""
;
}

$r .= $r1.$r2
;

}

echo
"<div class=/"code/">".$r."</div>"
;
}
}

?>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics