<?php
// Diese Alternative zur function highlight_file()
// ersetzt das font-tag mit span in phpversion<5
// und setzt ein Klassen-Attribut für das CSS-Styling:

function my_highlight_file($input_filename$return=false) {

    if( 
version_comparephpversion(),'5' )== -) {
        
$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;
}
// example:
$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>