Passing HTML string or HTML file to fwrite

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pablo1999
Forum Newbie
Posts: 6
Joined: Fri Mar 31, 2006 8:36 pm

Passing HTML string or HTML file to fwrite

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

have you tried it?
pablo1999
Forum Newbie
Posts: 6
Joined: Fri Mar 31, 2006 8:36 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you could simply replace .tmp with .html, or append .html to the string tempnam() returns.
Post Reply