According to your code, you’re already building the XML content yourself. XML files are just regular text files, so in this case you don’t need any of the special XML functions that validate and render. Instead, you can simply save your text to the .xml file:
file_put_contents('/tmp/test.xml', $xmlBody);
file_put_contents
allows you to forego all the fopen/fwrite functions, so it’s the easiest way to write content to disk.
On the other hand, if you do want to learn to build a structured XML document with all the bells and whistles of consistency, look up SimpleXML
or XMLWriter
. A little more overhead that way, but doing all the markup by hand can be unwieldy, especially when one typo can invalidate your whole document.
0
solved Creating/Writing an XML file in PHP?