2014-11-06 33 views
0

我正在製作一個抓取電子郵件地址的URL的抓取工具。但不知何故,它缺少電子郵件地址,並返回空數組的地方。PHP履帶失蹤命中並且空的命中

代碼:

function curl($url){ 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL,$url); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
     $return = curl_exec($ch); 
     curl_close ($ch); 
     return $return; 
    } 
    if(isset($_POST['go'])) 
    { 
     if($_POST['url'] != ''){ 
     $data = curl($_POST['url']); 
     preg_match("/[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})/i", $data, $matches); 
     echo "<h1>Handmatig gezocht</h1><hr>"; 
     $tely = count($matches); 
     for ($y=0; $y<=$tely; $y++) 
     { 
      if(!empty($matches[$y])) 
      { 
       echo $matches[$y] ."<br>"; 
      } 
      else 
      { 
       echo "Lege array :(<br>"; 
      } 
     } 
     echo "<hr>"; 

     } 
    } 

我做了一個簡單的網頁在我的本地主機上有5封電子郵件

<p>[email protected]</p> 
    <p>[email protected]</p> 
    <p>[email protected]</p> 
    <p>[email protected]</p> 
    <p>[email protected]</p> 

和陣列我從我的履帶式回看起來喜歡這樣的:

Array ([0] => [email protected] [1] => [2] => [3] => .nl) 

回答