I'm using PHP Simple HTML DOM Parser. In the page which I want to parse the images 'src' attribute is replaced with 'data-src'. So, if I try to get the image path using the following code, it will return nothing:
$elimage = $offer->find('div.photo', 0);
$im = $elimage->last_child('a');
$img = $im->last_child('img');
$item['image'] = $img->src;
I've tried to do it like this, but it does not work either:
$elimage = $offer->find('div.photo', 0);
$im = $elimage->last_child('a');
$img = $im->last_child('img');
$item['image'] = $img->data-src;
Does anybody know if that's possible to get the value of a custom attribute and, if yes, how can that be achieved?
Thanks for helping!
instead of
$img->data-src;
use
$img->{'data-src'};
taken from here
Anyway, I was about to find a solution to this kind of problem and stumble here then suddenly got an idea.
Just put it in variable first:
$dataSrc='data-src';
$item['image'] = $img->$dataSrc;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With