Snippet
<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;
padding-left: 8px;
border-right: 1px #999999 solid;
color: #777777;
}
div.sourceCode {
float: middle;
}
span.v {
color: #0000BB;
}
span.k {
color: #007700;
}
span.s {
color: #DD0000;
}
span.c {
color: #FF8000;
}
</style>
</head>
<body>
<?php
$filename = 'forum/admin.php';
ob_start();
highlight_file($filename);
$source = ob_get_contents();
ob_end_clean();
$source = explode(chr(13), $source);
$source = implode('', $source);
$source = explode(chr(10), $source);
$source = implode('', $source);
$source = explode('<br />', $source);
$source[0] = substr($source[0], 35);
$source[count($source) - 1] = substr($source[count($source) - 1], 0, strlen($source[count($source) - 1]) - 14);
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>
Copy & Paste
|