How do I open a file to write content to?



How do I open a file to write content to?..

Answer / 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

More PHP Interview Questions

when we use ob_start() function in php then the header() and session_start() does not gives the error like header already sent,please explain in brief

2 Answers  


Which is better #define or enum?

0 Answers  


What is preg_match?

0 Answers  


What is the use of mvc in php?

0 Answers  


What is var_dump function in php?

0 Answers  






how to change the div background color on every refresh..guys can u help me out.

3 Answers  


How session manage in wordpress

1 Answers   HCL, ITBS, TCS,


What is a query give example?

0 Answers  


In php, how to redirect from one page to another page?

0 Answers  


What the difference between the 'bitwise and' operator and the 'logical and' operator?

0 Answers  


What are major variables in research?

0 Answers  


Tell me how can I display text with a php script?

0 Answers  


Categories