Codice PHP:
$file='log.htm';
    if (
file_exists ($file)==false)
    {
        
$str  ="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
        
$str .="<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
        
$str .="<head>\n";
        
$str .="<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
        
$str .="<title>Debug applicazione</title>\n";
        
$str .="<link href=\"../css/class.debug.css\" rel=\"stylesheet\" type=\"text/css\" />\n";
        
$str .="</head>\n";
        
$str .="<body>\n";
        
$str .="[_CODE_] \n";
        
$str .="</body>\n";
        
$str .="</html>\n";

        
$id_file fopen($file'w+');
        
fwrite($id_file$str);
        
fclose($id_file);
    }
    
    
//leggo il file
$file_htm    file_get_contents($file)
$id_file fopen($file'r');

       
//effettuo la sostituzione e aggiungo [_CODE_]
    
$file_htm preg_replace("/\[_CODE_\]/""<span class=\"TestoCodice\">: XXXXXXXXx </span>[_CODE_]",$file_htm ,1);

    
$id_file fopen($file'w');
    
fwrite($id_file$file_htm);
    
fclose($id_file);

?>