|
PHP Syntax Highlighter
Well I created this simple script to help someone else on the site, figured I'd put it in its own thread. It basically uses the the PHP function highlight_file() to perform the standard PHP syntax highlighting. However, the limitation is that it didn't have line numbers. So I tweaked the output of that function a bit in order to also output line numbers.[PHP]<pre>
<?php
$filename = 'forum/admin.php';
ob_start();
highlight_file($filename);
$source = ob_get_contents();
ob_end_clean();
$source = explode(chr(13), $source);
$temp = substr($source[0], 0, 35);
$temp .= substr($source[0], 36);
$source[0] = substr($temp, 6);
$temp = substr($source[count($source) - 1], 0, strlen($source[count($source) - 1]) - 8);
$source[count($source) - 1] = $temp;
for($i = 1; $i < count($source); $i++){
$source[$i] = substr($source[$i], 6);
}
for($i = 0; $i < count($source) - 1; $i++){
$source[$i] .= '<br />';
}
$spaces = strlen(count($source));
for($i = 0; $i < count($source); $i++){
$source[$i] = '<span style="color: #777777">' . ($i + 1) . '</span> ' . $source[$i];
for($j = 0; $j < $spaces - strlen($i + 1); $j++){
$source[$i] = ' ' . $source[$i];
}
}
for($i = 0; $i < count($source); $i++){
echo $source[$i];
}
?>
</pre>[/PHP]
__________________
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
|