Reputation: 502
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&d=identicon&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!
Upvotes: 1
Views: 89
Reputation: 540
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&d=identicon&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">');
Upvotes: 2
Reputation: 838
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);
Upvotes: 5