note 27654 added to function.highlight-file
| From: | matt at rack1 dot php dot net | Date: | Sat, 14 Dec 2002 10:30:27 +0000 |
| Subject: | note 27654 added to function.highlight-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-40900@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.
--
http://www.php.net/manual/en/function.highlight-file.php
http://master.php.net/manage/user-notes.php?action=edit+27654
http://master.php.net/manage/user-notes.php?action=delete+27654
http://master.php.net/manage/user-notes.php?action=reject+27654