0

I am using simple html dom. I hav this code:

<html>
<div class="one">
<div class="two">this is inner text </div>
<a href="#" class="three">this is inner anchor</a>
This is outer test
</div>
</html>

I want to fetch This is outer test only. Here is my code :

$html = file_get_html(SITE_URL.'/forumlist.php');  
$html->find('.two',0)->outertext = "";
$html->find('.three',0)->outertext = "";
$html->save();
echo $html->find('.one',0)->plaintext;

and I got disappointed..

j0k
  • 22,600
  • 28
  • 79
  • 90
Prajwol Onta
  • 1,448
  • 5
  • 21
  • 48

1 Answers1

1

As far as I read the documentation, I don't think you can get that out as easy as you imagine ( I might be wrong of course ), but you can just remove the unneeded strings manually with str_replace:

$string = '<html>
<div class="one">
<div class="two">this is inner text </div>
<a href="#" class="three">this is inner anchor</a>
This is outer test
</div>
</html>';

$html = str_get_html( $string );
echo str_replace(
        array(
            $html->find('.two',0)->plaintext,
            $html->find('.three',0)->plaintext
        ),
        null,
        $html->find('.one',0)->plaintext
    );

This should actually do the trick, if you know the structure of the html.

Peon
  • 7,902
  • 7
  • 59
  • 100