在一行内使用highlight_string函数
来源:振中的技术记事本 责任编辑:栏目编辑 发表时间:2013-07-01 12:41 点击:次
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("(</?php )+", "", highlight_string("<?php ".$code_line, 1))."<br />";
}
} else {
相关新闻>>
- 发表评论
-
- 最新评论 更多>>