View Single Post
Old Mar 19th, 2007, 3:34 PM   #8
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
I remade the code and cut it down so it would be less memory intense by replacing some style codes with a main style sheet and also used css to control the spacing of the line numbers to decrease the number of &nbsp's that were necessary. The ones in the sourcecode still remain. Also, when there was a linewrap this would produce errors so I imposed a no linewrapping property in the style. However, this ONLY works in FIREFOX. For whatever reason Internet Explorer chooses to mess up the css as it sees fit.[PHP]<html>
<head>
<title>Grim PHP Syntax Highlighter</title>
<style type="text/css">
body {
font-family: Courier New;
font-size: 10pt;
white-space: nowrap;
}
div.lineNumbers {
float: left;
text-align: right;
margin-right: 8px;
padding-right: 8px;
border-right: 1px #999999 solid;
color: #777777;
}
span.v {
color: #0000BB;
}
span.k {
color: #007700;
}
span.s {
color: #DD0000;
}
span.c {
color: #FF8000;
}
</style>
</head>
<body>
<?php
$filename = 'forum/board_lib.php';
ob_start();
highlight_file($filename);
$source = ob_get_contents();
ob_end_clean();
$source = explode(chr(13), $source);
$source[0] = substr($source[0], 36);
$temp = substr($source[count($source) - 1], 0, strlen($source[count($source) - 1]) - 15);
$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 />';
}
echo '<div class="lineNumbers">' . "\n";
for($i = 0; $i < count($source); $i++){
echo $i + 1 . '<br />' . "\n";
}
echo '</div>' . "\n";
echo '<div class="sourceCode">' . "\n";
$source = implode("\n", $source);
$source = str_replace('<span style="color: #0000BB">', '<span class="v">', $source);
$source = str_replace('<span style="color: #007700">', '<span class="k">', $source);
$source = str_replace('<span style="color: #DD0000">', '<span class="s">', $source);
$source = str_replace('<span style="color: #FF8000">', '<span class="c">', $source);
echo $source;
echo '</div>' . "\n";
?>
</body>
</html>[/PHP]Styx, I don't get the errors you mention, that's why I'm not sure how they're occurring on your end. It seems like you're always missing a letter somewhere.
__________________
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