note 21905 deleted from function.highlight-file by aidan
| From: | aidan@php.net | Date: | Sun, 26 Sep 2004 13:58:00 +0000 |
| Subject: | note 21905 deleted from function.highlight-file by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77388@lists.php.net to get a copy of this message | ||
Note Submitter: jsweat_php xSPAM AT yahoo DOT xSPAM com
----
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.