Self Highlighting Code
| From: | Matt Hillebrand | Date: | Sat, 14 Dec 2002 02:27:05 +0000 |
| Subject: | Self Highlighting Code | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-128240@lists.php.net to get a copy of this message | ||
Using some borrowed code from www.php.net, I came up with this chunk of
code that can be included at the top of a PHP script to make it
highlight itself in a web browser. However, the first opening PHP tag in
the output has a space or two in front of it. Does anyone know why?
<?
print "<style>.ln{color:#000000;width:40px;font:normal 10px
courier;}</style>"; // _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. ";
?>