note 21905 added to function.highlight-file
| From: | jsweat_php@php.net | Date: | Thu, 30 May 2002 21:39:20 +0000 |
| Subject: | note 21905 added to function.highlight-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-31241@lists.php.net to get a copy of this message | ||
I needed to add line numbers to the output. Here is what I came up with:
Add this style to the head of your document:
<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;
}
the ob_ is a hack because PHP returned an error when I tried to use the second parameter to return
the output as a string.
The strlen line is also a hack because the IE was wraping very long lines on top of the next line
for some reason.
Similar code to the person who contributed a note on the show_source function. Hope it is useful to
someone.
--
http://www.php.net/manual/en/function.highlight-file.php
http://master.php.net/manage/user-notes.php?action=edit+21905
http://master.php.net/manage/user-notes.php?action=delete+21905
http://master.php.net/manage/user-notes.php?action=reject+21905