2016-09-16 62 views
-1

收錄我發現谷歌一個腳本考覈指標,如果網站已收錄如何檢查如果有更多的網站在谷歌

function getPagesIndexedGoogle($site) 
{ 
    if ($site) { 
     $curl = curl_init(); 
     curl_setopt_array($curl, array(
      CURLOPT_HEADER => 0, 
      CURLOPT_RETURNTRANSFER => 1, 
      CURLOPT_URL => "https://www.google.com.au/search?q=site:$site&gws_rd=ssl", 
      CURLOPT_SSL_VERIFYPEER=> false, 
      CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko' 
     )); 
     $result_string = curl_exec($curl); 
     curl_close($curl); 
     if (strpos($result_string, "did not match any documents") !== false) { 
      return 0; 
     } else { 
      $match = preg_match("/about ([0-9,]{0,12})/i", $result_string, $matches); 

      echo $matches[1]; 
     } 
    } 
} 

if($_POST['domain']){ 
    $site = $_POST['domain']; 
} 
echo $_POST['domain'] ; 
echo getPagesIndexedGoogle($site);  

?> 

如何檢查mutilple網址是什麼?

我已經使用了Foreach,但它不起作用。請幫幫我。

+0

'$ sites = array(「site1」,「site2」,「site3」); foreach($ sites爲$ site){echo getPagesIndexedGoogle($ site); }' - 當然用真實網站替換數組值。 – icecub

+0

護目鏡主動檢測刮刀,期待很快被堵塞。 – nogad

+0

謝謝。我使用Form let get Data。

Domain:
Steven

回答

0

按照要求,這應該做的伎倆:

<?php 

function getPagesIndexedGoogle($site) 
{ 
    if ($site) { 
     $curl = curl_init(); 
     curl_setopt_array($curl, array(
      CURLOPT_HEADER => 0, 
      CURLOPT_RETURNTRANSFER => 1, 
      CURLOPT_URL => "https://www.google.com.au/search?q=site:$site&amp;gws_rd=ssl", 
      CURLOPT_SSL_VERIFYPEER=> false, 
      CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko' 
     )); 
     $result_string = curl_exec($curl); 
     curl_close($curl); 
     if (strpos($result_string, "did not match any documents") !== false) { 
      return 0; 
     } else { 
      $match = preg_match("/about ([0-9,]{0,12})/i", $result_string, $matches); 

      echo $matches[1]; 
     } 
    } 
} 

if(!empty($_POST['domain'])){ 

    // Tries to split URLs by new line or space character 
    $sites = preg_split('#\\r\\n|\\r|\\n| #i', $_POST['domain']); 

    foreach($sites as $site){ 
     // Checks if the URL is a valid website or not (http(s):// must be included!) 
     if(preg_match('#((https?|ftp):\/\/(\S*?\.\S*?))([\s)\[\]{},;"\':<]|\.\s|$)#i', $site)){ 
      echo $site; 
      echo getPagesIndexedGoogle($site); 
     } else { 
      echo $site; 
      echo " is not a valid url."; 
     } 
    } 

} else { 
    echo "No websites were entered."; 
} 

?> 

我還是建議你不要用一個文本,但文本字段的簡單替代。它不太容易出錯。

+0

親愛的icecub,我用你的代碼,但顯示錯誤:意外的'{'。我發現行如果(preg_match但沒有看錯誤,請幫助我 – Steven

+0

@Steven這是一個簡單的錯誤,修正了它。 – icecub

+0

@iceclub它的工作,非常感謝。 – Steven

相關問題