亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用file_get_contents作為數組獲取圖像

如何使用file_get_contents作為數組獲取圖像

PHP
慕絲7291255 2021-04-30 13:45:02
我在將圖像獲取為數組時遇到以下問題。在這段代碼中,我試圖檢查是否Test 1存在要搜索的圖像-如果是,則顯示,如果不顯示,然后嘗試,僅Test 2此而已。當前的代碼可以做到,但是速度非常慢。這if (sizeof($matches[1]) > 3) {是因為3有時它包含爬網網站上的廣告,所以這是我安全的跳過方法。我的問題是我如何才能加快下面的代碼的if (sizeof($matches[1]) > 3) {速度呢?我相信這會使代碼非常慢,因為此數組可能包含多達1000個圖像$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;  }}
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 263 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號