function match_links($document) {
preg_match_all("']+))[^>]*>?(.*?)'isx",$document,$links);
while(list($key,$val) = each($links[2])) {
if(!empty($val))
$match['link'][] = $val;
}
while(list($key,$val) = each($links[3])) {
if(!empty($val))
$match['link'][] = $val;
}
while(list($key,$val) = each($links[4])) {
if(!empty($val))
$match['content'][] = $val;
}
while(list($key,$val) = each($links[0])) {
if(!empty($val))
$match['all'][] = $val;
}
return $match;
}
主要是正則的問題,下面給出個asp.net下的,多測試正則
獲取頁面的鏈接正則
public string gethref(string htmlcode)
{
string matchvale = "";
string reg = @"(h|h)(r|r)(e|e)(f|f) *= *('|"")?((\w|\\|\/|\.|:|-|_)+)('|""| *|>)?";
foreach (match m in regex.matches(htmlcode, reg))
{
matchvale += (m.value).tolower().replace("href=", "").trim() + "||";
}
return matchvale;
}
希望與廣大網友互動??
點此進行留言吧!