Ich muss wissen, wie ich den Inhalt des Tags (nicht Attribute, nur Inhalt) ändern. Ich brauche keine inneren Tags in diesem Eltern-Tag. Ich muss nur einen Text hineinstecken. (Ersetzen Sie "1. Hallo Welt") der nächsten XML-Datei:SimpleXMLElement Wie ändere ich den Tag-Inhalt (Wert)
<config name="THIS" type="string">1. Hello World)</config>
<config name="IS" type="string">2. Hello World!</config>
<config name="SPARTA" type="string">3. Hello World?</config>
// create simple xml object
$xml = new SimpleXMLElement(file_get_contents('file.xml'));
// new names and values
$names = array('THIS', 'SPARTA');
$values = array('1. Good bye world(', '3. Good bye world?');
// replace here
foreach($xml as $a => $xmlElement) {
$indexOfName = array_search($names, (string)$xmlElement['name']);
if ($indexOfName !== false) {
// here I need to replace the value (e.g. 1. Hello World)) of config
// with the attribute @name == $names[$i] with the new value
// $values[$i] (3. Good bye world?)
}
}
Ich habe dies bereits versucht. Es hat nicht funktioniert – pleerock