我正在制作一个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>jamie@jamie.nl</p>
<p>test@test.nl</p>
<p>dasd@dsad.nl</p>
<p>addasd@dasvfv.nl</p>
<p>gsdgseg@sdfsdfsd.nl</p>
我从爬行器回来的数组看起来像这样:
Array ( [0] => jamie@jamie.nl [1] => [2] => [3] => .nl )