I use the following code to cut out a div from a site.
$url = 'http://mypage.com/index.php';
$html = @file_get_html($url);
$GetScore = $html->find('div[class=ismSBValue]',0);
echo $GetScore;
This returns.....
<div class="ismSBValue">
<div> 58
<sub>pts</sub>
</div>
</div>
How do I cut out ONLY the 58 value?
I can do the following...
$GetScore = $html
->find('div[class=ismSBValue]',0)
->find('div',0)
->innertext;
to get it down to this....
58
<sub>pts</sub>
Is there some way to exclude the <sub>
tag using simple_html_dom? or am I stuck to using str_replace()
or strpos()
to cut it further?
clone then delete u dont want
JAVASCRIPT
$(function(){
var a = $('.ismSBValue').clone();
a.find('sub').remove();
console.log($.trim(a.text()));
})
PHP
$html = str_get_html('<div class="ismSBValue">
<div> 58
<sub>pts</sub>
</div>
</div>');
$html->find('div[class=ismSBValue]',0)->find('div',0)->find('sub',0)->innertext = '';
$a = $html->find('div[class=ismSBValue]',0)->plaintext;
echo trim($a); //58
Don't remove the sub
, you might need it later. A simple regex will work:
preg_match('/\d+/', $html->find('div.ismSBValue div', 0)->text(), $match);
echo($match[0]); // 58