note 27654 deleted from function.highlight-file by nicos
| From: | nicos@php.net | Date: | Sun, 15 Dec 2002 10:57:52 +0000 |
| Subject: | note 27654 deleted from function.highlight-file by nicos | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-40928@lists.php.net to get a copy of this message | ||
Oh, man, did I get carried away on this one...
This code does syntax highlighting and line numbering in style:
<?
$contents = highlight_file($filename, true);
$contents = explode('<br />', $contents);
print '<html><head><style>';
print 'body,code,font,span{font:normal 10px Fixedsys; margin:0px}';
print '.ln{margin:0px; margin-right:4px; padding:0px; padding-right:2px; text-align:right;
color:#ffffff; background-color:#666666; width:45px}';
print '</style></head><body>';
$ln = 1;
foreach($contents as $line) {
if(strstr($line, '<code>'))
$line = '<code><font color=#000000>'.substr($line, 29);
print "<span class=ln>$ln</span>$line<br>";
$ln++;
}
print '</body></html>';
?>
Again, the BR is missing where I printed $line because of this message board. The substr() is a hack
that's necessary to remove the unwanted space mentioned above.