title: How to remove attributes using PHP DOMDocument?
body: <p>With this piece of XML:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;my_xml&gt;
    &lt;entities&gt;
      &lt;image url="lalala.com/img.jpg" id="img1" /&gt;
      &lt;image url="trololo.com/img.jpg" id="img2" /&gt;
    &lt;/entities&gt;
  &lt;/my_xml&gt; 
  </code></pre>
  
  <p>I have to get rid of all the attributes within the image tags. So, I've done this:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  $article = &lt;&lt;&lt;XML
  &lt;my_xml&gt;
    &lt;entities&gt;
      &lt;image url="lalala.com/img.jpg" id="img1" /&gt;
      &lt;image url="trololo.com/img.jpg" id="img2" /&gt;
    &lt;/entities&gt;
  &lt;/my_xml&gt;  
  XML;
  
  $doc = new DOMDocument();
  $doc-&gt;loadXML($article);
  $dom_article = $doc-&gt;documentElement;
  $entities = $dom_article-&gt;getElementsByTagName("entities");
  
  foreach($entities-&gt;item(0)-&gt;childNodes as $child){ // get the image tags
    foreach($child-&gt;attributes as $att){ // get the attributes
      $child-&gt;removeAttributeNode($att); //remove the attribute
    }
  }
  
  ?&gt;
  </code></pre>
  
  <p>Somehow when I try to remove an from attribute within the foreach block, it looks like the internal pointer gets lost and it doesn't delete both the attributes.</p>
  
  <p>Is there another way of doing that?</p>
  
  <p>Thanks in advance.</p>