Lines numbers
Posted: Fri Nov 25, 2005 12:37 pm
I'm trying to print out source code with a line number next to each line.
This function kind of works, but first off the code goes past the numbers.
This is my source code:
$code being the source code to display.
A live example of this can be viewed here
This function kind of works, but first off the code goes past the numbers.
This is my source code:
Code: Select all
$lines = explode("\n", $code);
$numbers = "";
$final = "";
for($x = 1; $x <= 100; $x++) {
$number = $x . "<br \>\n";
$numbers .= $number;
$line = $lines[$x - 1] . "<br \>\n";
$final .= $line;
}
echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td width=\"1%\" align=\"right\" valign=\"top\">
$numbers
</td>
<td width=\"1%\" valign=\"top\">
</td>
<td width=\"98%\" align=\"left\" valign=\"top\">
$final
</td>
</tr>
</table>";
}A live example of this can be viewed here