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;
}
希望与广大网友互动??
点此进行留言吧!