这个脚本会帮助你!!尝试这个 :)
<?php
function replace_Special_Str($mystring)
{
//Load file
$filename="./myfile.xml";
if (!file_exists($filename)) { echo "There is not a myfile.xml file in the directory."; exit;}
$xml = simplexml_load_file($filename);
//search and replace particular node by book title
$node = $xml->xpath('/datas/books[title="' . $mystring. '"]');
if(sizeof($node) > 0)
{
$node[0]->title = 'My Title';
}
$xml->asXML('./aucstatus.xml');
}
?>
或者试试这个,
<users>
<name>John</name>
<address>My Address</address>
<zipcode>12345</zipcode>
<city>My City</city>
<phone>555 1234-4321</phone>
</users>
PHP文件
fopen('users.xml');
while ($users->read()) {
switch ($users->nodeType) {
case (XMLReader::ELEMENT):
if ($users->localName == "users") {
$node = $reader->expand();
$dom = new DomDocument();
$n = $dom->importNode($node,true);
$dom->appendChild($n);
$simple_xml = simplexml_import_dom($n);
$id = $simple_xml['id'];
$name = $simple_xml->name;
$address = $simple_xml->address;
// Custom code insert, update, whatever...
}
}
}