note 27668 added to function.highlight-file
| From: | matt at rack1 dot php dot net | Date: | Sun, 15 Dec 2002 01:31:37 +0000 |
| Subject: | note 27668 added to function.highlight-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-40917@lists.php.net to get a copy of this message | ||
Sorry to post so many times, but this script is the ULTIMATE for highlighting with line numbers:
<?
$contents = highlight_file($filename, true);
$contents = explode('<br />', $contents);
print
'<html><head><style>body,code,font,td{font-family:Fixedsys,"Courier
New", Courier;margin:0px}';
print '.ln{margin:0px;padding:0px;padding-right:2px;
color:#ffffff;background-color:#666666;width:45px}';
print '</style></head><body>';
print '<table border=0 cellpadding=0 cellspacing=0><tr><td class=ln
align=right valign=top nowrap>';
for($i=1; $i<=sizeof($contents); $i++)
print "$i<br>";
print '</td><td style="cursor:normal"> </td><td
nowrap>';
foreach($contents as $line)
print "$line<br>";
print '</td></tr></table></body></html>';
?>
And then for making a file highlight itself, you could include this code:
<?
$contents = highlight_file(basename($_SERVER['PHP_SELF']), true); // _ignore_
$contents = explode('<br />', $contents); // _ignore_
print
'<html><head><style>body,code,font,td{font-family:Fixedsys,"Courier
New", Courier;margin:0px} '; // _ignore_
print '.ln{margin:0px;padding:0px;padding-right:2px;
color:#ffffff;background-color:#666666;width:45px}'; // _ignore_
print '</style></head><body>'; // _ignore_
print '<table border=0 cellpadding=0 cellspacing=0><tr><td class=ln
align=right valign=top nowrap>'; // _ignore_
$ln=1; // _ignore_
foreach($contents as $line) if(!strstr($line, '// _ignore_')) { print
"$ln<br>"; $ln++; } // _ignore_
print '</td><td style="cursor:normal"> </td><td
nowrap>'; // _ignore_
foreach($contents as $line) if(!strstr($line, '// _ignore_')) print
"$line<br>"; // _ignore_
print '</td></tr></table></body></html>'; exit; //
_ignore_
?>
--
http://www.php.net/manual/en/function.highlight-file.php
http://master.php.net/manage/user-notes.php?action=edit+27668
http://master.php.net/manage/user-notes.php?action=delete+27668
http://master.php.net/manage/user-notes.php?action=reject+27668