2011-01-09 91 views
-1

嘿,我正在尋找一種方法來替換另一個元素值。我想到的是,當一個變量等於「刺客信條:兄弟會」時,這個值被一個新的替代。我的項目是用simplexml(添加,刪除)開發的,但DOM也很讚賞。感謝您的幫助!用XML替換元素值php

我的XML是

<Game type="adventure"> 
<TITLE>Assassin's Creed: Brotherhood</TITLE> 
<PUBLISHER>Ubisoft</PUBLISHER> 
</Game> 

+0

的[替換字符串在PHP變種 - XML]可能重複(HTTP:// stackoverflow.com/questions/4632548/replace-string-with-var-in-php-xml) – 2011-01-09 19:41:38

回答

0

用SimpleXML:

$games = simplexml_load_file('games.xml'); 
foreach ($games as $game) { 
    if ($game->TITLE == "Assassin's Creed: Brotherhood") { 
     $game->TITLE = "Kiss Me Kate"; 
    } 
} 
$games->asXML('games2.xml');