View Single Post
Old Mar 19th, 2007, 1:36 PM   #6
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
I improved the code to be able to select only the source code without the line numbers getting selected:[PHP]<html>
<head>
<title>Grim PHP Syntax Highlighter</title>
<style>
div.lineNumbers {
float: left;
text-align: left;
border-right: 1px #999999 solid;
margin-right: 8px;
}
</style>
</head>
<body>
<span style="font-family: Courier New; font-size: 10pt">
<?php
$filename = 'syntax_h.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 />';
}
$lineNum = array();
$spaces = strlen(count($source));
for($i = 0; $i < count($source); $i++){
array_push($lineNum, '<span style="color: #777777">' . ($i + 1) . '</span>&nbsp;');
for($j = 0; $j < $spaces - strlen($i + 1); $j++){
$lineNum[$i] = '&nbsp;' . $lineNum[$i];
}
$lineNum[$i] .= '<br />';
}
echo '<div class="lineNumbers">';
for($i = 0; $i < count($lineNum); $i++){
echo $lineNum[$i];
}
echo '</div>';
echo '<div class="sourceCode">';
for($i = 0; $i < count($source); $i++){
echo $source[$i];
}
echo '</div>';
?>
</span>
</body>
</html>[/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
grimpirate is offline   Reply With Quote