0
我使用preg_match_all其返回該錯誤:preg_match_all返回一個錯誤未定義,偏移
Notice: Undefined offset: 0 in B:\xampp\htdocs\fogsy\link_searcher.php on line 98
,這是第98行:
$server_name=$matches[0][1]."/";
這裏是我的功能: 它是用來檢索鏈接來自html正文。
function GetLinks($body_str,$parent_url)
{
$url_list=array();
preg_match_all('/http:\/\/(.*)\//iU', $parent_url, $matches, PREG_SET_ORDER);
$server_name=$matches[0][1]."/";
preg_match_all('/< *a.*href *= *[\'"](.*)[\'"].*>(.*)< *\/a *>/iU', $body_str, $matches, PREG_SET_ORDER);
for($count=0;$count<count($matches);$count++)
{
$text=$matches[$count][2];
if(strpos(strtolower($matches[$count][1]),"http://")===false&&strpos(strtolower($matches[$count][1]),"www")===false)
$href="http://".$server_name.trim($matches[$count][1],"/");
else $href=$matches[$count][1];
$url_list[$text."_".$count]=$href;
}
return $url_list;
}
有什麼想法嗎?
哦。疑難雜症。謝謝 – cppit 2013-02-28 07:14:44
@fogsy:酷:D – 2013-02-28 07:15:29