Cannot get availabe products information using PHP Simple HTML DOM

I am trying to get some information from this web page: Here is a screenshot:

enter image description here

I want to extract the “10 available” info and I am using the span id qtySubTxt , however my code does not reach the actual value. Here is my code:

   $available = $html->find("#qtySubTxt", 0);
            if($sold != null){
                $item['available'] = $available->plaintext;
                $item['available'] = '';

I debugged the DOM element but I am confused how to reach the text. Here is my debugged info from the DOM element:

enter image description here

php dom

You seem to have A LOT of simple DOM questions lately… but yet you never come back to reply after answers are given?

Told you before about a different approach then how YOU are using the ‘find’ method…

There is also a nested sub SPAN tag that holds your inner text.

            $available = $html->getElementById("qtySubTxt");
            if($available != null){
                $item['available'] = trim($available->nodeValue);
                $item['available'] = '';

I found a solution but it stills returns Null for the $item['available']

Several things…

1.) not sure why you changed to getElementById?

2.) The eBay auction listing is actually invalid markup. You are only supposed to have 1 id (ID’s are supposed to be unique)… however… for whatever reason they are listing ‘2’ DOM elements with the same ID

3.) Had you looked over my last attempt to help in your other SIMPLE DOM thread… you would have seen the answer there as well…

This work just fine for me:

(pretty simple)

$html = file_get_html('');
$available = $html->find('#qtySubTxt')[1];
echo $available;



Returns *null* if no elements with the specified ID exists.

An ID should be unique within a page. However, if more than one element with the specified ID exists, the getElementById() method returns the first element in the source code.
Sponsor our Newsletter | Privacy Policy | Terms of Service