I am collecting all images from web page. But as there might be some icons with .png
which are also considered as image.
Is that possible for me to show only real images, not a icons or favicon on page?
HEre is my simple script
function get_logo($html,$url)
{
$url = rtrim($url, '/');
if (strpos($url,'wikipedia') !== false)
return "http://upload.wikimedia.org/wikipedia/commons/5/53/Wikipedia-logo-en-big.png";
else if(preg_match_all('/\bhttps?:\/\/\S+(?:png|jpg)\b/', $html, $matches))
{
return $matches;
}
else
{
preg_match_all("/<img src=\"(.*?)\"/", $html, $matches);
return $url.''.$matches[1][0];
}
}
one of the result:
array (size=1)
0 =>
array (size=16)
0 => string 'http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon@2.png' (length=63)
1 => string 'https://i.stack.imgur.com/tKsDb.png' (length=34)
2 => string 'https://i.stack.imgur.com/tKsDb.png' (length=34)
3 => string 'https://i.stack.imgur.com/tKsDb.png' (length=34)
4 => string 'https://i.stack.imgur.com/uE37r.png' (length=34)
5 => string 'https://i.stack.imgur.com/tKsDb.png' (length=34)
6 => string 'https://i.stack.imgur.com/tKsDb.png' (length=34)
7 => string 'https://i.stack.imgur.com/tKsDb.png' (length=34)
8 => string 'https://i.stack.imgur.com/dmHl0.png' (length=34)
9 => string 'https://i.stack.imgur.com/tKsDb.png' (length=34)
10 => string 'https://i.stack.imgur.com/dmHl0.png' (length=34)
11 => string 'https://i.stack.imgur.com/tKsDb.png' (length=34)
12 => string 'https://i.stack.imgur.com/uE37r.png' (length=34)
13 => string 'https://i.stack.imgur.com/NG6TX.png' (length=34)
14 => string 'https://i.stack.imgur.com/BfCOt.png' (length=34)
15 => string 'https://i.stack.imgur.com/tKsDb.png' (length=34)