How do I open a file to write content to?
Answer Posted / jude jeevanraj.p
Working with files and folders in PHP is fairly easy though
it can take a little while to get used to.
You need to create a filehandle, which is a pointer to a
file, that you wish to write too.
Use the fopen function to open a file, and pass the name of
the file as the first parameter and what you want to do
with it second - in this case 'w' for write.
Then simple use fwrite to write to your file, and close it
with fclose.
Here's a simple example that will create a file in the
directory called example.txt and write to it with just a
few lines of PHP code.
<?php
$myfile = fopen("example.txt","w");
fwrite($myfile,"That was easy!");
fclose($myfile);
?>
| Is This Answer Correct ? | 5 Yes | 0 No |
Post New Answer View All Answers
What is the difference between require_once and require in php?
How can we change the value of a constant?
What is the function mysql_pconnect() useful for?
How can php and javascript interact?
How do we get the current session id?
How cookies are transported from browsers to servers?
Tell me how can we determine whether a variable is set?
What is difference between require_once(), require(), include()?
What is final class and final method in php?
What is sql injection in php?
Explain how is it possible to cast types in php?
How to read the entire file into a single string?
Difference between get and post method.
Can I learn laravel without php?
Does php need to be installed?