note 27640 added to function.highlight-file
| From: | matt at rack1 dot php dot net | Date: | Fri, 13 Dec 2002 21:00:24 +0000 |
| Subject: | note 27640 added to function.highlight-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-40880@lists.php.net to get a copy of this message | ||
Here is a chunk of code you can put at the top of a file to make it highlight itself (with line
numbers). I added the CSS stuff to make the left hand margin a uniform width.
<?
print "<style>.ln{color:#000000;width:30px;font-size:12px;}</style>\n"; //
_ignore_
$contents = highlight_file(basename($_SERVER['PHP_SELF']), true); // _ignore_
$contents = explode("<br />", $contents); // _ignore_
$ln = 1; // _ignore_
foreach($contents as $line) if(!strstr($line, "_ignore_")) { print "<span
class=ln>$ln:</span>$line<br>"; $ln++; } // _ignore_
exit; // _ignore_
print "Hello, cruel world. ";
while(true)
print "God I love PHP. ";
?>
Note that BRs don't display in this forum. The $line variable needs a BR after it when printed.
For some reason, the first line of the output doesn't want to obey...
--
http://www.php.net/manual/en/function.highlight-file.php
http://master.php.net/manage/user-notes.php?action=edit+27640
http://master.php.net/manage/user-notes.php?action=delete+27640
http://master.php.net/manage/user-notes.php?action=reject+27640