0

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!

2
  • doesn't the plaintext property return what you want? Commented Dec 27, 2013 at 4:02
  • Did you look at the examples here: simplehtmldom.sourceforge.net/manual.htm Commented Dec 27, 2013 at 4:03

1 Answer 1

2

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

$scraped_seats = (int)$getSeats->plaintext;
1
  • Thanks so much, Jack! That was it, I had to use that format. It's now successfully converting to an int I can use. Commented Dec 27, 2013 at 4:53

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.