View Single Post
Old Mar 19th, 2007, 1:13 PM   #5
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 431
Rep Power: 4 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
Here's what I get:
 1 <pre>
 2 <?php
 3 $filename = 'syntax_h.php';
 4 ob_start();
 5 highlight_file($filename);
 6 $source = ob_get_contents();
 7 ob_end_clean();
 8 $source = explode(chr(13), $source);
 9 $temp = substr($source[0], 0, 35);
10 $temp .= substr($source[0], 36);
11 $source[0] = substr($temp, 6);
12 $temp = substr($source[count($source) - 1], 0, strlen($source[count($source) - 1]) - 8);
13 $source[count($source) - 1] = $temp;
14 for($i = 1; $i < count($source); $i++){
15     $source[$i] = substr($source[$i], 6);
16 }
17 for($i = 0; $i < count($source) - 1; $i++){
18     $source[$i] .= '<br />';
19 }
20 $spaces = strlen(count($source));
21 for($i = 0; $i < count($source); $i++){
22     $source[$i] = '<span style="color: #777777">' . ($i + 1) . '</span>&nbsp;' . $source[$i];
23     for($j = 0; $j < $spaces - strlen($i + 1); $j++){
24         $source[$i] = '&nbsp;' . $source[$i];
25     }
26 }
27 for($i = 0; $i < count($source); $i++){
28     echo $source[$i];
29 }
30 ?>
31 </pre>
I'm not sure why yours isn't getting the same thing. But your code also produced proper output so whatever works ^_^. Also, the idea behind using &nbsp instead of the space character is so that rather than using the pre html tag the user can use a span with another monospaced font. For instance, something like this: <span style="font-family: Courier New; font-size: 10pt"> which produces the same results.
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote