drl92080 2013-12-27 03:55
浏览 48
已采纳

PHP字符串到Int转换丢失值(使用simple_html_dom)

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条回答 默认 最新

  • dsiy62758 2013-12-27 04:02
    关注

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

    $scraped_seats = (int)$getSeats->plaintext;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序