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 inheritance in php with example?
Tell me how is it possible to know the number of rows returned in result set?
How can you send email in php?
How do http requests work?
What is php and its features?
Tell me how is the ternary conditional operator used in php?
What is composer phar?
Can we override static method?
What are classes in php?
Is array function in php?
Where is session id stored?
Tell me what does the scope of variables means?
What is symfony php?
Write a program to swap two numbers using php.
How to delete a file from the system?