1

I am using simple_html_dom, i am having issues grabbing a div with a class name specified below is the code!

<?php
include 'simple_html_dom.php';
$html='
   <div class="user-info ">
    <div class="user-action-time">
        answered <span title="2016-06-27 20:01:45Z" class="relativetime">Jun 27 at 20:01</span>
    </div>
    <div class="user-gravatar32">
        <a href="/users/25355/david-mulder"><div class="gravatar-wrapper-32"><img src="https://www.gravatar.com/avatar/09e3746cf7e47d4b3b15f5d871b91661?s=32&amp;d=identicon&amp;r=PG" alt="" width="32" height="32"></div></a>
    </div>
    <div class="user-details">
        <a href="/users/25355/david-mulder">David Mulder</a>
        <div class="-flair">
           '; 
echo $html->find('div[class=user-details]',0);
    ?>

What am i doing wrong here i am getting error Call to a member function find() on string in

Thanks!

7
  • 1
    you need to work on your question's title. Edit: Oh, this as per original stackoverflow.com/revisions/38918520/1 just in case people ask ;-) Commented Aug 12, 2016 at 12:58
  • It's like trying to attract/catch mice with cheese; they actually don't eat "cheese" ;-) but they love bran muffins though!!! @StackB00m Commented Aug 12, 2016 at 13:00
  • 2
    its usefull comment @StackB00m, if you use proper title, than u will get more answers. Commented Aug 12, 2016 at 13:00
  • 1
    Maybe you have the 'Call to a member function find() on string' error because $html is a string. Commented Aug 12, 2016 at 13:01
  • 1
    You need to call str_get_html(). Commented Aug 12, 2016 at 13:02

2 Answers 2

5

You are tying to use Simple Html Dom to parse an html string.

Do not assign your html string to $html variable. Assign it to an other, like $html_string. Then use $html = str_get_html($html_string) and echo $html->find('div[class=user-details]',0);

Sign up to request clarification or add additional context in comments.

1 Comment

Oops yes that was so stupid of me i forgot doing this thanks for reminding :)
2

You trying to call object method on a string variable. It should works:

$html = str_get_html('<div class="user-info ">
    <div class="user-action-time">
        answered <span title="2016-06-27 20:01:45Z" class="relativetime">Jun 27 at 20:01</span>
    </div>
    <div class="user-gravatar32">
        <a href="/users/25355/david-mulder"><div class="gravatar-wrapper-32"><img src="https://www.gravatar.com/avatar/09e3746cf7e47d4b3b15f5d871b91661?s=32&amp;d=identicon&amp;r=PG" alt="" width="32" height="32"></div></a>
    </div>
    <div class="user-details">
        <a href="/users/25355/david-mulder">David Mulder</a>
        <div class="-flair">');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.