$html = file_get_contents('http://www.test.com);
$file = '/Applications/MAMP/htdocs/test.html';
file_put_contents($file,$html);
Does file_put_content create the file test.html when file doesn't exists?
The file_put_contents() function checks for the file in which the user wants to write and if the file doesn't exist, it creates a new file.
PHP Create File - fopen() The fopen() function is also used to create a file. Maybe a little confusing, but in PHP, a file is created using the same function used to open files. If you use fopen() on a file that does not exist, it will create it, given that the file is opened for writing (w) or appending (a).
The file_put_contents() function returns the number of bytes that were written to the file, or FALSE on failure.
yes.
as per php documentation:
If filename does not exist, the file is created.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With