title: Removing nested tags with simpleHTML
body: <p>I'm trying to use simple_html_dom to remove all the spans from a snippet of HTML, and I'm using the following:</p>
  
  <pre><code>$body = "&lt;span class='outer' style='background:red'&gt;x&lt;span class='mid' style='background:purple'&gt;y&lt;span class='inner' style='background:orange'&gt;z&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;";
  $HTML = new simple_html_dom;
  $HTML-&gt;load($body);   
  $spans = $HTML-&gt;find('span');
  foreach($spans as $span_tag) {
      echo "working on ". $span_tag-&gt;class . " ... ";
      echo "setting " . $span_tag-&gt;outertext . " equal to " . $span_tag-&gt;innertext . "&lt;br/&gt;\n";
      $span_tag-&gt;outertext = (string)$span_tag-&gt;innertext;
  }
  $text =  $HTML-&gt;save();
  $HTML-&gt;clear();
  unset($HTML);
  echo "&lt;br/&gt;The Cleaned TEXT is: $text&lt;br/&gt;";
  </code></pre>
  
  <p>And here's the result in my browser:</p>
  
  <p><a href="http://www.pixeloution.com/RAC/clean.gif" rel="nofollow noreferrer">http://www.pixeloution.com/RAC/clean.gif</a></p>
  
  <p>So why is it I'm only ending up with the outer most span removed? </p>
  
  <h3>Edit</h3>
  
  <p>Actually if there's an easier way to do this, I'm game. The object is to remove the  tags but keep anything inside them including other tags, or else I'd just use $obj->paintext</p>
  
  <h3>Edit #2</h3>
  
  <p>Okay ... apparently I got it working, although oddly enough I'd still like to actually understand the problem if anyone ran into this before. Knowing it was only removing the outermost span, I did this:</p>
  
  <pre><code>function cleanSpansRecursive(&amp;$body) {
  
      $HTML = new simple_html_dom;
      $HTML-&gt;load($body); 
      $spans = $HTML-&gt;find('span');
      foreach($spans as $span_tag) {
          $span_tag-&gt;outertext = (string)$span_tag-&gt;innertext;
      }
  
      $body =  (string)$HTML;
      if($HTML-&gt;find('span')) {
          $HTML-&gt;clear();
          unset($HTML);
          cleanSpansRecursive($body);
      } else {
          $HTML-&gt;clear();
          unset($HTML);
      }  
  }
  </code></pre>
  
  <p>And it seems to work.</p>