i did something like this but I instead of outputting xml in a php file i outputted a php array to a new file. here's what I used, it may help you to create the function you need:
$f=fopen("db.php","w"); fwrite($f, str_replace("$", "$", "<?php ".$output."?>")); fclose($f);
I doubt you'll need the st_rreplace in there but if you have any special characters that mess up the script like the $ it may be usefull. if the file does not exist, it wil attempt to create it, assuming you have your directory's permissions set so a new file can be created.hope this helps, i didnt go through those other links so if its the same im sorry... im just too lazy haha