title: DOM removing selected child nodes
body: <p>I have a dom element with html inside chat contains some html elements I'd like to remove, while still keeping some tags that are ok.</p>
  
  <p>I try to iterate through child elements all child elements and delete those that need to be removed </p>
  
  <pre><code>foreach ($node-&gt;getElementsByTagName('*') as $element)
      if ($element-&gt;nodeName != 'br')
          $node-&gt;removeChild($element);
  </code></pre>
  
  <p>But this throws a Not Found Error exception which not being caught causes a fatal error.
  How would I solve this problem ?</p>