Skip to content

Instantly share code, notes, and snippets.

@SumonMSelim
Created July 8, 2019 09:19
Show Gist options
  • Save SumonMSelim/a3c0da243ee5019e0a5db606f1050330 to your computer and use it in GitHub Desktop.
Save SumonMSelim/a3c0da243ee5019e0a5db606f1050330 to your computer and use it in GitHub Desktop.
php append to file
<?php
$tag_to_add = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>';
$file = 'file.xml';
// Using file_put_contents()
$myfile = file_put_contents($file, $tag_to_add.PHP_EOL , FILE_APPEND | LOCK_EX);
// Using fwrite()
$fstream = fopen($file, 'a');
fwrite($fstream, '\n'. $tag_to_add);
fclose($fstream);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment