Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Simple HTML DOM can't read "data-src" or "img src" without http: in path

Tags:

php

I'm working with PHP Simple HTML DOM and just discovered it can't read images from data-src attribute or <img src without http: eg; <img src="//static.mysite.com/123.jpg">

Is there any way to make it happen?

My code is:

if($htm->find('img')){
foreach($htm->find('img') as $element) {
        $raw = file_get_contents_curl($element->src);
        $im = @imagecreatefromstring($raw);
        $width = @imagesx($im);
        $height = @imagesy($im);
        if($width>500&&$height>=350){
    $hasimg = '1';
        echo '<img src=\'' .$element->src. '\'>';
        }

} // end foreach
} // end if htm
like image 962
wp student Avatar asked Jul 23 '26 15:07

wp student


2 Answers

It works for me:

$doc = str_get_html('<img data-src="foo">');
echo $doc->find('img', 0)->getAttribute('data-src');
//=> outputs: foo
like image 135
pguardiario Avatar answered Jul 25 '26 04:07

pguardiario


echo $htm->find('img', 0)->getAttribute('data-src');
like image 29
Ali Emadzadeh Avatar answered Jul 25 '26 06:07

Ali Emadzadeh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!