С этой частью XML:Как удалить атрибуты с помощью PHP DOMDocument?
<my_xml>
<entities>
<image url="lalala.com/img.jpg" id="img1" />
<image url="trololo.com/img.jpg" id="img2" />
</entities>
</my_xml>
Я должен избавиться от всех атрибутов в пределах тегов изображений. Таким образом, я сделал это:
<?php
$article = <<<XML
<my_xml>
<entities>
<image url="lalala.com/img.jpg" id="img1" />
<image url="trololo.com/img.jpg" id="img2" />
</entities>
</my_xml>
XML;
$doc = new DOMDocument();
$doc->loadXML($article);
$dom_article = $doc->documentElement;
$entities = $dom_article->getElementsByTagName("entities");
foreach($entities->item(0)->childNodes as $child){ // get the image tags
foreach($child->attributes as $att){ // get the attributes
$child->removeAttributeNode($att); //remove the attribute
}
}
?>
Как-то, когда я пытаюсь удалить из атрибута в блоке Еогеаспа, это выглядит как внутренний указатель теряется и не удаляет как атрибутов.
Есть ли другой способ сделать это?
Заранее спасибо.
BINGO! Я использую первый подход. Большое спасибо! (два других тоже хорошо работают) – romulodl