Reputation: 4452
In PHP, i have a $string
that contains XML-structured data.
How can i create and save a XML file from $string
?
Appreciate any help.
Upvotes: 10
Views: 25645
Reputation: 1040
For just storing the XML to a file, go with Teneff's answer.
But if you also want to parse the XML, use SimpleXML
(or even better: XMLReader
/ XMLWriter
).
Of course, you could also use DOM
, but out of all the possibilities around, this would be the slowest and most memory consuming one.
Upvotes: 0
Reputation: 380
You can use DOM to load the XML string http://www.php.net/manual/en/domdocument.loadxml.php
and then use DOM to save the XML to file http://www.php.net/manual/en/domdocument.save.php
Upvotes: 2