Warptweet Posted January 12, 2007 Share Posted January 12, 2007 I got an answer before, but was very vague and didn't exactly answer the question...Is it possible to write HTML or PHP to a file?If so, can you please explain how?Thanks,-Warptweet Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 12, 2007 Share Posted January 12, 2007 Exactly the same as you would write text to a file. Save the file as .php instead of .txt, and make sure to use your <?php ?> tags. Quote Link to comment Share on other sites More sharing options...
zfred09 Posted January 12, 2007 Share Posted January 12, 2007 try thisob_start();?><---make sure you close your php here<html></html><?phpchdir("directory");$fp = fopen("$filename.php", "w") ;fwrite($fp, ob_get_contents());fclose($fp);ob_end_flush(); Quote Link to comment Share on other sites More sharing options...
scotmcc Posted January 12, 2007 Share Posted January 12, 2007 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 Quote Link to comment Share on other sites More sharing options...
Warptweet Posted January 12, 2007 Author Share Posted January 12, 2007 Okay...Well, one of you says to do it as I would any other PHP... Except save it as a .php file when I create the file..Now, two of you are saying two different methods, this is seriously confusing. Can you please tell me the sure fire way? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 12, 2007 Share Posted January 12, 2007 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. Quote Link to comment Share on other sites More sharing options...
scotmcc Posted January 12, 2007 Share Posted January 12, 2007 My code seems to work on my server :)Scot Quote Link to comment Share on other sites More sharing options...
Warptweet Posted January 12, 2007 Author Share Posted January 12, 2007 I presumed your code would work, although I have not tried it yet.I'm busy doing the uploader part, I'll try soon. Quote Link to comment Share on other sites More sharing options...
Guest Posted February 15, 2007 Share Posted February 15, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.