note 70456 added to function.highlight-string
| From: | vanessaschissato at gmail dot com | Date: | Tue, 17 Oct 2006 15:04:55 +0000 |
| Subject: | note 70456 added to function.highlight-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-118617@lists.php.net to get a copy of this message | ||
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 {
$r2 = (!$line) ? "<pre>" : "";
$r2 .= htmlentities($code_line);
$r2 .= ($line == ($count_lines - 1)) ? "<br /></pre>" : "";
}
$r .= $r1.$r2;
}
echo "<div class=\"code\">".$r."</div>";
}
}
?>
----
Server IP: 200.185.109.13
Probable Submitter: 143.106.1.71 (proxied: 143.106.80.79)
----
Manual Page -- http://www.php.net/manual/en/function.highlight-string.php
Edit -- https://master.php.net/note/edit/70456
Del: integrated -- https://master.php.net/note/delete/70456/integrated
Del: useless -- https://master.php.net/note/delete/70456/useless
Del: bad code -- https://master.php.net/note/delete/70456/bad+code
Del: spam -- https://master.php.net/note/delete/70456/spam
Del: non-english -- https://master.php.net/note/delete/70456/non-english
Del: in docs -- https://master.php.net/note/delete/70456/in+docs
Del: other reasons-- https://master.php.net/note/delete/70456
Reject -- https://master.php.net/note/reject/70456
Search -- https://master.php.net/manage/user-notes.php