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?
This might work :
<style type="text/css"> code { color: rgb(0,0,255) } .c2 { position:absolute; left:45; white-space: nowrap; } .nw { white-space: nowrap; } </style>
and then use this function on a file: function highlight_file_rownums( $file ) { ob_start(); highlight_file($file); $data = ob_get_contents(); ob_end_clean();
$data_lines = explode('<br />',$data);
for ($i=0, $j=count($data_lines); $i < $j; $i++) {
$k = $i + 1;
$ret .= '<div class="nw"><code>'.$k.'</code><span class="c2">'.$data_lines[$i]."</span></div>\n";
if (strlen($data_lines[$i]) > 450) {
$ret .= '<br />';
}
}
return $ret;
}
http://www.php.net/manual/en/function.highlight-file.php
-- Burhan Khalid phplist[at]meidomus[dot]com
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php