Salve a tutti,
ho creato questo script che genera un file html con il corpo una stringa "[_CODE_]". Devo cercare questa stringa e sostituirla con un'altra stringa e salvare il tutto.
Ho scritto questo ma nn vA!!!! Taglia il codice html.
Dove sbaglio?
Grazie
codice:
$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');
fputs($id_file, $str, strlen($str));
fclose($id_file);
}
//leggo il file
$id_file = fopen($file, 'r');
$file_htm=fgets($id_file,filesize($file)+1);
fclose($id_file);
//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');
fputs($id_file, $file_htm, strlen($file_htm));
fclose($id_file);
?>
Salva solo questa riga:
codice:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">