Q. Adding line numbers to highlighted source
| From: | Alan McFarlane | Date: | Fri, 04 Apr 2003 05:27:55 +0000 |
| Subject: | Q. Adding line numbers to highlighted source | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-142256@lists.php.net to get a copy of this message | ||
I've been trying to add line-numbers to my source code, but can't seem to
work out how to do it.
As an example, I tried the following:
<?php
function addPrefix( $matches )
{
static $line = 1;
return $line++ . $matches[0];
}
$url = split("\?", $_GET['url']);
$source = highlight_file($url[0], true);
$source = preg_replace_callback("
\<br \/\>U", "addPrefix",
$source);
echo $source;
?>
which is called whenever the use user on a link like <a
href="show-source.php?url=index.php">Show Source</a>
The problem is that my regex does not correcly match the lines.
Anyone got any bright ideas?
--
Alan McFarlane