TouchOfDarkness |
27-03-2003 15:53 |
Citaat:
Martin schreef op 27-03-2003 @ 08:50:
Hmm, de code staat al pasklaar op hun forum :-)
*klik*
|
deze gebruiken wij nu:
PHP-code:
function phphighlite($code) {
//PHP 4 only
if (floor(phpversion())<4) {
$buffer = $code;
} else {
$code = str_replace("<br>", "", $code);
$code = str_replace("<br />", "", $code);
$code = str_replace(">", ">", $code);
$code = str_replace("<", "<", $code);
$code = str_replace("&", "&", $code);
$code = str_replace('$', '\$', $code);
$code = str_replace('\n', '\\\\n', $code);
$code = str_replace('\r', '\\\\r', $code);
$code = str_replace('\t', '\\\\t', $code);
$code = stripslashes($code);
if (!strpos($code,"<?") && substr($code,0,2) != "<?") {
$code = "<?\n".trim($code)."\n?>";
$addedtags = 1;
}
ob_start();
$oldlevel=error_reporting(0);
highlight_string(trim($code));
error_reporting($oldlevel);
$buffer = ob_get_contents();
ob_end_clean();
if ($addedtags) {
$openingpos = strpos($buffer,'<?');
$closingpos = strrpos($buffer, '?');
$buffer = trim(substr($buffer, 0, $openingpos) . substr($buffer, $openingpos+5, $closingpos-($openingpos+5)) . substr($buffer, $closingpos+5));
}
$buffer = str_replace(""", "\"", $buffer);
$buffer = preg_replace("#(<br />)(];)#mU", "\\2", $buffer);
$buffer = preg_replace("/<font color=\"(#)?[0-9a-fA-F]+\"><br \/><\/font>/Ums", "", $buffer);
$newline_count = count(explode("<br />", $buffer));
$returntable = "<table cellpadding=\"0\" cellspacing=\0\" style=\"border: 1px solid #000000;\" width=\"100%\">\n";
$returntable .= "<tr valign=\"top\">\n<td align=\"center\" bgcolor=\"#D9D9D9\" width=\"25\" style=\"font-family: Courier; font-size: 12px; line-height: 12px;\" nowrap>\n";
for($i = 1; $i <= $newline_count; $i++) {
$returntable .= "$i<br />\n";
}
$returntable .= "</td>\n";
$returntable .= "<td bgcolor=\"#FFFFFF\" style=\"font-family: Courier New; font-size: 12px; padding-left: 3px; padding-top: 0px; padding-right: 1px; line-height: 12px;\" nowrap>$buffer</td>\n";
$returntable .= "</tr>\n</table>";
}
return "</normalfont><blockquote><smallfont>PHP:</smallfont>$returntable</blockquote><normalfont>";
}
|