Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
php append to file
$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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment