下面的代码查找给定网站上的所有图像并返回最大的图像,但速度非常慢。任何人都可以帮忙吗?谢谢!
$largest = 0;
$images = array();
reg_match_all('/(img|src)\=(\"|\')[^\"\'\>]+/i', $html, $media);
unset($html);
$data=preg_replace('/(img|src)(\"|\'|\=\"|\=\')(.*)/i',"$3",$media[0]);
foreach($data as $imgUrl) {
$info = pathinfo($imgUrl);
if (isset($info['extension'])) {
if (($info['extension'] == 'jpg') ||
($info['extension'] == 'jpeg') ||
($info['extension'] == 'gif') ||
($info['extension'] == 'png')) {
array_push($images, $imgUrl);
$imgUrl = $this->rel2abs($imgUrl, $this->url);
list($width, $height, $type, $attr) = getimagesize($imgUrl);
$size = $width * $height;
if ($size > $largest) {
$this->image = $imgUrl;
$largest = $size;
}
}
}