tags:

views:

68

answers:

4

I have the following html:

<html>
 <body>
 bla bla bla bla
  <div id="myDiv"> 
         more text
      <div id="anotherDiv">
           And even more text
      </div>
  </div>

  bla bla bla
 </body>
</html>

I want to remove everything starting from <div id="anotherDiv"> until its closing <div>. How do I do that?

+1  A: 

u can use preg_replace like :

$string = preg_replace('/<div id="someid'[^>]+\>/i', "", $string);
Haim Evgi
this will remove all `div`s and not only the specified one.
jigfox
You don't specify anywhere that it must remove the div with the ID=myDiv?
RD
he update the question.. , now i update mine
Haim Evgi
+1  A: 

strip_tags() function is what you are looking for.

http://us.php.net/manual/en/function.strip-tags.php

drpcken
trip_tags() doesn’t work the way he want it to. strip_tags() allows for certain exclusions, but why would you use that when you only want to exclude one tag and include all other tags
Haim Evgi
From his question, I couldn't really tell what tags he was trying to remove. It seemed as if he wanted to remove everything. Thanks for the input.
drpcken
Ahhh, using chrome. His inline markup didn't show up. I just checked it in firefox and I see his inline markup. You are correct :) Any reason why it didn't show up in chrome?
drpcken
+2  A: 

You can also use Simple HTML DOM for that.

A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way!

Sarfraz
+2  A: 

With native DOM

$dom = new DOMDocument;
$dom->loadHTML($htmlString);
$xPath = new DOMXPath($dom);
$nodes = $xPath->query('//*[@id="anotherDiv"]');
if($nodes->item(0)) {
    $nodes->item(0)->parentNode->removeChild($nodes->item(0));
}
echo $dom->saveHTML();
Gordon