Hey I am looking for a way to replace an element value with another. What I have in mind is when a variable is equal to "Assass开发者_开发问答in's Creed: Brotherhood", this value is replaced by a new one. My project is developed with simplexml ( add, delete) but DOM is appreciated too. Thank you for your help!
My XML is
<Game type="adventure">
<TITLE>Assassin's Creed: Brotherhood</TITLE>
<PUBLISHER>Ubisoft</PUBLISHER>
</Game>
With 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');
精彩评论