PHP String to Int Conversion Losing Value (using simple_html_dom)

本小妞迷上赌 提交于 2019-12-25 06:45:26

问题


so I'm using simple_html_dom to parse a page for elements with a particular class. I successfully retrieve those elements but cannot seem to get them converted into usable variables (ie an integer so I can do an 'if' statement).

It seems they are an object of some kind, and I've searched everywhere for hours, but no luck. There doesn't seem to be much support for simple_html_dom.

Here's my code:

///////////////
$html = new simple_html_dom();  

// Load a file 
$html->load_file($getURL); 
$getName = $html -> find('.ddlabel', 0);
$getSeats = $html->find('.dddefault', 3); 
///////////////

$scraped_name = "$getName";
$scraped_seats = "$getSeats";

$seats = intval($scraped_seats);

echo $scraped_name . "<br>" . $scraped_seats . "<br><br>";
echo gettype($seats) . "<br>" . $seats . "<br>";

// If seats are avavilable, send a message
if ($seats !== 0) { ... }

Some of the echos are just for purposes of me trying to figure this out. Also I might add that all this code in in a foreach() loop, not sure if that matters. I'm reading a csv file of things to append to a url and that's what the foreach() loop is for. But I don't think that's messing with the problem I have.

Thanks for any help!


回答1:


According to the documentation you would have to extract the content:

$scraped_seats = (int)$getSeats->plaintext;


来源:https://stackoverflow.com/questions/20794506/php-string-to-int-conversion-losing-value-using-simple-html-dom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!