0
嗨,我想知道如何使用PHP正確如何做到這一點。閱讀xml使用PHP來代替標籤
- 加載XML文檔
- 查找和替換文本
- 保存在新名稱的XML
XML數據是在這裏着張貼在這裏,由於未知的原因。 http://pastebin.com/A3rDtwzp
我想在兩個內容標籤之間找到文本,並用當前年份替換所有xml中的所有標籤。
另外,如果可以請指導我簡單的方法謝謝。
謝謝!
嗨,我想知道如何使用PHP正確如何做到這一點。閱讀xml使用PHP來代替標籤
XML數據是在這裏着張貼在這裏,由於未知的原因。 http://pastebin.com/A3rDtwzp
我想在兩個內容標籤之間找到文本,並用當前年份替換所有xml中的所有標籤。
另外,如果可以請指導我簡單的方法謝謝。
謝謝!
加載XML文檔
<?php
// Issues an E_STRICT error
$doc = DOMDocument::loadXML('<root><node/></root>');
echo $doc->saveXML();
?>
查找和替換文本
<?php
// The text string
$text = "The quick brown fox jumped over the lazy dog.";
// The word we want to replace
$oldWord = "brown";
// The new word we want in place of the old one
$newWord = "blue";
// Run through the text and replaces all occurrences of $oldText
$text = str_replace($oldWord , $newWord , $text);
// Display the new text
echo $text;
?>
答案的3
<?php
$docfile = new DOMDocument();
$eleT = $docfile->createElement('Root');
$eleT->nodeValue = 'Hello XML World';
$docfile->appendChild($eleT);
$docfile->save('MyXmlFile.xml');
?>
我希望所有的人一起工作:P喜歡的Open XML(HTTP: //pastebin.com/A3rDtwzp)找到並替換文本並保存thnx :) – user2951768