Jump to content

Writing HTML or PHP to a file?


Warptweet

Recommended Posts

To write data to a file:

<?php
$text = "<p>Write this to a file.</p>"; 
$file = "myfile.html"; 
if (!$my_file = fopen($file,"a")) {
echo "Unable to open $file";

if (!fwrite($my_file, $text)) {
echo "Unable to write to $file";

echo "Text entered into $file"; 
fclose($my_file); 
?>

Scot McConnaughay
How about you try them both and find out. I would put all the PHP code in a big string, and write it to a file. But because I don't really care, I haven't tried it. You care. Try it.

I didn't say write it as php, I said as any file. You'd put a string of text in a file.
$str = "Text".
Do
$str "<?php print 'hello world';?> ";
Does it work? I don't know. But it won't kill you to try since you want to do it.
  • 1 month later...
I've done this before. Jesirose's suggestion to do (as quoted)

$str = "<?php print 'hello world'; ?>";

will work. I've used this method to create cleanup scripts on-the-fly to unlink temp files and unnecessary scripts useless to the application after a script installation finishes.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.