<?php
function my_highlight_file($input_filename, $return=false) {
if( version_compare( phpversion(),'5' )== -1 ) {
$tag ='font';
$attr='color="';
$match = array('</font>');
$replace = array('</span>');
} else {
$tag = 'span';
$attr ="style=\"color: ";
$match = array();
$replace = array();
}
$nodetypes = array(
'string',
'comment',
'keyword',
'default',
'html'
);
foreach ($nodetypes as $nodetype) {
ini_set("highlight.$nodetype", $nodetype);
}
$string = highlight_file($input_filename,true);
foreach ($nodetypes as $nodetype) {
$match[] = '<'.$tag.' '.$attr.$nodetype.'">';
$replace[] = '<span class="'.$nodetype.'">';
ini_restore("highlight.$nodetype");
}
$string = str_replace($match,$replace,$string);
if($return) {
return $string;
} else echo $string;
}
$code = my_highlight_file(__FILE__,true);
?>
<!DOCTYPE HTML>
<html>
<title>Alternative zur function highlight_file() mit CSS-Styling</title>
<head>
<style type="text/css">
span.string {
color:#d00;
}
span.comment {
font-family:'Courier New',Courier,sans-serif;
color:#ff8000;
}
span.keyword {
color:#070;
font-weight:bold;
}
span.default {
color:#00b;
}
span.html {
color:#000;
font-size:8pt;
font-family:Verdana;
}
</style>
</head>
<body>
<?php echo $code;?>
</body>
</html>