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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

  • 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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.