Export results to a txt file



I coded something to export data from an xml into a txt:


For example, the xml display keywords between multiple tags.


Then, it create a txt one keyword per line like this:



keyword1
keyword2
etc...


Here is the code i made:



<?php
$xml=simplexml_load_file("thexml.xml") or die("Error: Cannot create object");
foreach($xml->children() as $screenname) {
$nick = $screenname->screenname;
file_put_contents('online.txt',$nick . "\n",FILE_APPEND);
}
?>


The problem is I want to overwrite the online.txt each time i run the script. If i delete ,FILE_APPEND from the script, it just outputs the first result. If i run the script with FILE_APPEND, i just adds more keyword to the last txt created each time i run the script.


Thanks for your help.


No comments:

Post a Comment