Page 1 of 1

Passing HTML string or HTML file to fwrite

Posted: Fri Apr 14, 2006 11:26 pm
by pablo1999
How can I pass an an html string to fwrite?

Is this the correct way?

Code: Select all

<?php

fwrite($fp, "<b>First Name:</b> $body<br>");


?>



Or, how to pass an HTML file to fwrite?

Is this the correct way?

Code: Select all

<?php

fwrite($fp, "myfile.html");


?>



Thank you in advanced.

Posted: Fri Apr 14, 2006 11:28 pm
by feyd
have you tried it?

Posted: Sat Apr 15, 2006 12:36 am
by pablo1999
I wrote it like the following and it works.

Code: Select all

<?php


$body = "This is the body";
$filename = 'input.html';
$somecontent = "<html><body><b>First Name:</b> $technicalfirstname<br></body></html> ";


$handle = fopen($filename, 'w');

fwrite($handle, $somecontent);
    
print "Success, wrote ($somecontent) to file ($filename)";
    
fclose($handle);
                                        
?>


The problem is that I'm first using PHP's function tempnam to create the unique file where fwrite is going to write but I'm not able to specify ".html" as the extension when creating the file.

So when I read the file it shows all the html code.

Posted: Sat Apr 15, 2006 9:00 am
by feyd
you could simply replace .tmp with .html, or append .html to the string tempnam() returns.