note 94835 deleted from function.highlight-file by danbrown
| From: | danbrown@php.net | Date: | Fri, 27 Nov 2009 14:29:54 +0000 |
| Subject: | note 94835 deleted from function.highlight-file by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-163340@lists.php.net to get a copy of this message | ||
Note Submitter: HDF
----
This is a simple little code I use, to Syntax Highlight my own file with line numbers:
<style type="text/css">
.num {
color: gray;
text-align: right;
margin-right: 6pt;
padding-right: 6pt;
border-right: 1px solid gray;
width: 20px;
display: inline-block;
}
</style>
<?PHP
function highlight($file)
{
$code = explode("<br />", highlight_file($file, 1));
foreach ($code as $key => &$value) {
$add = "<span class=\"num\">" . ($key + 1) .
"</span>";
if ($key == 0) {
$value = substr($value, 0, 36) . $add . substr($value, 36);
} else {
$value = $add . $value;
}
}
echo implode("<br />", $code);
}
highlight(substr(strrchr($_SERVER["PHP_SELF"], '/'), 1));
?>