This is going to be hard to explain so please ask me for clarification if anything confuses you.
So let’s say that I am on createpage.php
. Within this page, I have the following tasks.
-
Create a new page (file) using PHP via
$file = fopen($pagename . '.php', "x")
. -
Add premade content to this new page.
The method that I am taking to add new content to the new page is by storing the HTML content code into one variable called $newpagecontent
. Then, I simply use fwrite($file, $newpagecontent)
.
The problem is though, that you can’t store the whole of HTML/PHP file into $newpagecontent without breaking the double quotes. For example, $newpagecontent="echo("hello!")"
.
So the question is, is there a better way to add in HTML content to a newly created page? or is there a way to store the HTML code into a variable without breaking the syntax?
Thanks a lot
Advertisement
Answer
If you just want the contents of the other file that contains the HTML/PHP code, then try file_get_contents
to read the contents and store it in the variable. Please see the documentation of this function for further details.