I have the following problem with getting images as array.
In this code I'm trying to check if images for search Test 1
exist - if yes, then display, if not then try with Test 2
and that's it. Current code can do it but is super slow.
This if (sizeof($matches[1]) > 3) {
because this 3
sometimes contains advertisement on crawled website, so this is my secure how to skip it.
My question is how I can speed up code below to get if (sizeof($matches[1]) > 3) {
faster? I believe that this makes code very slow, because this array may contain up to 1000 images
$get_search = 'Test 1';
$html = file_get_contents('https://www.everypixel.com/search?q='.$get_search.'&is_id=1&st=free');
preg_match_all('|<img.*?src=[\'"](.*?)[\'"].*?>|i', $html, $matches);
if (sizeof($matches[1]) > 3) {
$ch_foreach = 1;
}
if ($ch_foreach == 0) {
$get_search = 'Test 2';
$html = file_get_contents('https://www.everypixel.com/search?q='.$get_search.'&is_id=1&st=free');
preg_match_all('|<img.*?src=[\'"](.*?)[\'"].*?>|i', $html, $matches);
if (sizeof($matches[1]) > 3) {
$ch_foreach = 1;
}
}
foreach ($matches[1] as $match) if ($tmp++ < 20) {
if (@getimagesize($match)) {
// display image
echo $match;
}
}