Search code examples
phphtmlfunctionfwrite

Writing full 100+ lines of html to a file with php


I have a system set up where, when the user registers, it creates a custom directory for them and then inside that directory it creates a file called index.html. I would like to write an entire HTML page of 100+ lines to that file. I was using fopen() fwrite($filepath, 'content');, but there are escape characters like '' and "" that mess up the PHP function.

Is there a better way to write large content to these files, or should I just have the file saved somewhere on my webserver and then just transfer it to each new registered user?


Solution

  • If you already have the file on disk, and it will not change for each user, then you should copy the file.

    It is a waste of resources to read and then write the file with PHP..

    PHP Manual - copy