How to append to a file using PHP

To append to a file using PHP, following code snippet can be used:


......
......
$file = 'test.txt';
try
{
$fp = fopen($file, 'a');
fwrite($fp, "Appending to file"."\n\r");
fclose($fp);
}
catch(Exception $e){
echo "Writing into file throwing exception".$e;
}
.......
.......

Hope you find the information presented here useful. Please leave your queries or feedback in the comments section below.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">