10

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.

0

4 Answers 4

25

you can use:

file_put_contents("myxmlfile.xml", $string);
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

0

you can use file_put_contents for example

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.