title: DOM php delete all tags by tag name
body: <p>I'm having a problem with a script I've been using for some time and it worked for me until I hit this problem.</p>
  
  <p>I have a script with which I'd like to delete all p html tags from a html source code.
  The script does work partly because it only removes some of the p tags, but leaves some out.</p>
  
  <p>I don't understand why it does that.</p>
  
  <pre><code>$doc = new DOMDocument();
  
  $a = &lt;&lt;&lt;FAIL
  &lt;html&gt;&lt;body&gt;
  &lt;div style="clear:both"&gt;&lt;/div&gt;
  &lt;p class="articletitle"&gt;hoo&lt;/p&gt;
  &lt;p class="articletext"&gt;hmmm&lt;/p&gt;
  &lt;p class="articletext"&gt;hmmmm&lt;/p&gt;
  &lt;p align="center"&gt;&lt;/p&gt;
  &lt;/body&gt;&lt;/html&gt;
  FAIL;
  
  $doc-&gt;loadHTML($a);
  $list = $doc-&gt;getElementsByTagName("p");
  
  foreach ($list as $l) {
  $l-&gt;parentNode-&gt;removeChild($l);
  $c++;
  }
  echo $doc-&gt;saveHTML() . $c;
  </code></pre>
  
  <p>the script returns </p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"&gt;
  &lt;html&gt;&lt;body&gt;
  &lt;div style="clear:both"&gt;&lt;/div&gt;
  
  &lt;p class="articletext"&gt;hmmm&lt;/p&gt;
  
  &lt;p align="center"&gt;&lt;/p&gt;
  </code></pre>
  
  <p>leaving out two p tags... </p>
  
  <p>Can you please help me to find out why it's skipping some tags</p>