如何使用php写入现有的xml文件

Hi every one I have an XML file, it's contain same tags like this:

<data>
<info><detail>first data</detail></info>
<info><detail>second data</detail></info>
<info><detail>third data</detail></info>
....
</data>

I want to add this:

<info><detail>fourth data</detail></info>

to my file.

and thanks for any help.

$xml = simplexml_load_file('foo.xml');
$xml->addChild('info')->addChild('detail', 'fourth data');
file_put_contents('foo.xml', $xml->asXML());

Look into the simplexml extension for PHP

http://us3.php.net/simplexml

Specifically http://us3.php.net/manual/en/simplexmlelement.addchild.php for adding the node once you have created it.