PHP string for XML file

In PHP, I have a $string that contains XML structured data.

How can I create and save an XML file with $string ?

Appreciate any help.

+6
source share
4 answers

you can use:

 file_put_contents("myxmlfile.xml", $string); 
+16
source

You can use the DOM to load the XML string http://www.php.net/manual/en/domdocument.loadxml.php

and then use the DOM to save the XML file http://www.php.net/manual/en/domdocument.save.php

+2
source

you can use file_put_contents for example

0
source

To just save the XML to a file, go to the Teneff answer.

But if you also want to SimpleXML XML, use SimpleXML (or even better: XMLReader / XMLWriter ).

Of course, you can also use the DOM , but of all the features around it will be the slowest and most memory-consuming.

0
source

Source: https://habr.com/ru/post/907296/


All Articles