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
Are php variables global?
The left association operator % is used in PHP for?
What is the goto statement useful for?
How to concatenate two strings in php?
What is the difference between runtime exception and compile time exception?
How to get length of an array in PHP?
Explain me difference between mysql_connect and mysql_pconnect?
Which is the correct way to check if a session has already been started ?
What is a php session?
What is purpose of @ in Php?
What is the use of super-global arrays in php?
Tell me how do I escape data before storing it into the database?
Write a program to find no of days between two dates in php?
Tell me how can we display information of a variable and readable by human with php?
What is move_uploaded_file in php?