<?phpphp
$str ='<a id="top8" href="http://abc.com/song/A.htm" class="p14" target="_top">歌曲列表</a><br><a target="_blank" id="bp" href="http://bca.com/list/bangping.html" class="p14">中文金曲榜</a><br><td nowrap="nowrap"> <a id="top19" href="qingyinyue.html" class="p14" target="_top">輕音樂</a></td>';html
$str = $str ."<iframe src=\"/info/public/bipin.shtml\" id=\"leitai\" name=\"leitai\" frameborder=\"0\" scrolling=\"no\" width=\"100%\" height=\"307px;\"></iframe>";ide
//連接地址+標題(href必須帶雙引號)url
$pat ='/<a(.*?)href="(.*?)"(.*?)>(.*?)<\/a>/i';htm
preg_match_all($pat, $str, $m);ip
print_r($m[2]);get
print_r($m[4]);iframe
for($i=0;$i<count($m[2]) ;$i++){it
echo '<li><a href="'.$_SERVER['PHP_SELF'].'?url='.$m[2][$i].'">'.$m[4][$i].'</a></li>';class
}
echo "<hr />";
//僅連接地址(href必須帶雙引號)
preg_match_all('/(?<=href=")[\w\d\.:\/]*/',$str,$m);
print_r($m);
echo "<hr />";
//連接地址+標題(通用)
preg_match_all('/<a.*?(?: |\\t|\\r|\\n)?href=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>(.+?)<\/a.*?>/sim',$str,$m);
print_r($m[1]);
print_r($m[2]);
echo "<hr />";
//iframe地址(通用)
preg_match_all('/<iframe.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>(.*?)<\/iframe.*?>/sim',$str,$m);
print_r($m[1]);
?>