Well I finally found a workable solution:

$url = "index.php"; /* for example */
$source = explode("<br />", preg_replace("`\</?code\>`Ui", "",
highlight_file($url, true)));

for ($i = 0; $i < count ($source); $i++)
    $source[$i] = "<span style=\"color:black;\">" . str_pad($i, 5, "0",
STR_PAD_LEFT) . "</span> " . $source[$i];

echo "<code>" . implode("<br />", $source) . "</code>";




"Alan McFarlane" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to