Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    Creazione file HTML con php

    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">
    "Considerate la vostra semenza:
    fatti non foste a viver come bruti,
    ma per seguir virtute e canoscenza''."
    Dante Alighieri

  2. #2
    oddio...togli quei '\n' alla fine di ogni riga!!!

  3. #3
    Il motivo è questo?
    "Considerate la vostra semenza:
    fatti non foste a viver come bruti,
    ma per seguir virtute e canoscenza''."
    Dante Alighieri

  4. #4
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    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);

    ?> 
    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.