php - Why is this foreach failing? -



php - Why is this foreach failing? -

the script using 'gets' html page , parses showing .jpg images within, need create modifications , when fails...

this works:

include('simple_html_dom.php'); function geturladdress() { $url = $_server['https'] == 'on' ? 'https' : 'http'; homecoming $url .'://'.$_server['http_host'].$_server['request_uri']; } $html = file_get_html($url); foreach($html->find('img[src$=jpg]') $e) echo '<img src='.$e->src .'><br>';

however, there problems... want show images on size, plus site not display total url in img tag , need seek around too... have done following:

include('simple_html_dom.php'); function geturladdress() { $url = $_server['https'] == 'on' ? 'https' : 'http'; homecoming $url .'://'.$_server['http_host'].$_server['request_uri']; } $html = file_get_html($url); foreach($html->find('img[src$=jpg]') $e) $image = $e->src; // check see if src has domain if (preg_match("/http/", $e->src)) { $image = $image; } else { $parts = explode("/",$url); $image = $parts['0']."//".$parts[1].$parts[2].$e->src; } $size = getimagesize($image); echo "<br /><br />size {$size[0]}"; echo '<img src='.$image.'><br>';

this works, returns first image.

on illustration link below there 5 images, first code shows not display them src without leading domain

example link mentioned above

is there improve way this? , why loop fail?

you seem missing {:

foreach($html->find('img[src$=jpg]') $e) {

php html simple-html-dom

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -