久艹网,456看看亚洲,91色在线,国产一级特黄aaa片做受小说

中山php|最優(yōu)網(wǎng)絡(luò)中山做網(wǎng)站 中山php建站

最優(yōu)良人

2012/05/30 at 16:48

php采集程序,提取網(wǎng)頁超鏈接,郵箱或其他特定內(nèi)容

以下代碼從上一篇文章修改而來,專門用于提取網(wǎng)頁所有超鏈接,郵箱或其他特定內(nèi)容

<?php

function fetch_urlpage_contents($url){
$c=file_get_contents($url);
return $c;
}
//獲取匹配內(nèi)容
function fetch_match_contents($begin,$end,$c)
{
$begin=change_match_string($begin);
$end=change_match_string($end);
$p = "#{$begin}(.*){$end}#iU";//i表示忽略大小寫,U禁止貪婪匹配
if(preg_match_all($p,$c,$rs))
{
return $rs;}
else { return "";}
}//轉(zhuǎn)義正則表達(dá)式字符串
function change_match_string($str){
//注意,以下只是簡單轉(zhuǎn)義
$old=array("/","$",'?');
$new=array("\/","\$",'\?');
$str=str_replace($old,$new,$str);
return $str;
}

//采集網(wǎng)頁
function pick($url,$ft,$th)
{
$c=fetch_urlpage_contents($url);
foreach($ft as $key => $value)
{
$rs[$key]=fetch_match_contents($value["begin"],$value["end"],$c);
if(is_array($th[$key]))
{ foreach($th[$key] as $old => $new)
{
$rs[$key]=str_replace($old,$new,$rs[$key]);
}
}
}
return $rs;
}

$url="http://"; //要采集的地址
$ft["a"]["begin"]='<a'; //截取的開始點<br />
$ft["a"]["end"]='>'; //截取的結(jié)束點

$rs=pick($url,$ft,$th); //開始采集

print_r($rs["a"]);

?>

標(biāo)簽:,
-