关键语句:
@(.*?)<a\s([^>]*?)href=([\'\"\s]?)([^>\'\"\s]+)([\'\"\s]?)([^>]*?)>(.+?)</a>(.*)@is附带一个获取页面所有链接的例子:<?
$f=file('http://duan.onmoon.com');
$str="";
while(list($line_num,$line)=each($f))
{
$str.=$line;
}
$count=0;
$ptn="@(.*?)<a\s([^>]*?)href=([\'\"\s]?)([^>\'\"\s]+)([\'\"\s]?)([^>]*?)>(.+?)</a>(.*)@is";
while(preg_match($ptn,$str,$reg))
{
echo "-----------------------------------------------------------------------------------";
$count++;
echo "〖".$reg[4]."〗<br/>";
echo $count."【".$reg[7]."】<br/>";
$str=$reg[1].$reg[8];
}
?>
@(.*?)<a\s([^>]*?)href=([\'\"\s]?)([^>\'\"\s]+)([\'\"\s]?)([^>]*?)>(.+?)</a>(.*)@is附带一个获取页面所有链接的例子:<?
$f=file('http://duan.onmoon.com');
$str="";
while(list($line_num,$line)=each($f))
{
$str.=$line;
}
$count=0;
$ptn="@(.*?)<a\s([^>]*?)href=([\'\"\s]?)([^>\'\"\s]+)([\'\"\s]?)([^>]*?)>(.+?)</a>(.*)@is";
while(preg_match($ptn,$str,$reg))
{
echo "-----------------------------------------------------------------------------------";
$count++;
echo "〖".$reg[4]."〗<br/>";
echo $count."【".$reg[7]."】<br/>";
$str=$reg[1].$reg[8];
}
?>
你的结果好像不对,连怎么那么多<td>什么的?
我只需要的是<a 开始和 a>结束的内容。