大家好,讨论一下php抓取网址,请进来!!!! 利用正则提取所有的a标签,将链接地址(www.csdn.net)与内容(中国程序网)生成一个键与值对应的数组.比如$aArray['www.csdn.net'] = '中国程序网'。找的时候就很简单了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我这样找A标签可以吧? <a href=(.*?)>(.*)<\/a>/si function getValue($str, $start, $end, $start_num=1, $end_num=1){ if(empty($str))return ""; if(empty($start))return ""; if(empty($end))return ""; $pos1 = 0; for($i=0; $i<$start_num; $i++) { $pos1 = strpos($str, $start, $pos1); if($pos1===false) { return ""; } $pos1 = $pos1 + strlen($start); } $pos2 = $pos1; for($i=0; $i<$end_num; $i++) { $pos2 = strpos($str, $end, $pos2 + 1); if($pos2===false) { return ""; } } return substr($str, $pos1, $pos2 - $pos1);}$data = '<a href="http://www.csdn.net" target="_blank">中国程序员网</a><a href="http://www.msdn.com" target="_blank">外国程序员网</a><a href="http://www.mistruster.com" target="_blank">Mistruster</a>...';echo getValue($data, '<a href="', '"');echo "<br>\n";echo getValue($data, '<a href="', '"', 2);echo "<br>\n";echo getValue($data, '<a href="', '"', 3);//... 最快最准的还是正则VBScript正则<a href=(.*?) .*?>(.*?)<\a>循环\1和\2 alipay 查询订单信息 api 请大家帮忙一下,想批量下载Discuz官方论坛的一部分网页(完整的网页信息,事先登录),如何是好? 初學php求助 rawurlencode和urlencode分别应该在什么场合使用?请指点。 出个题 考考大伙儿 关于图片存储的问题 PHP“动态增加文本框”!! 求助 返回前一页面的PHP代码是什么?谢谢 托管的php网站上传图片有限制 请教,千万条记录怎么快速查询出来. a页面调用(include)b页面,b页面在被调用的时候能取到a页面的URL吗?
{
if(empty($str))return "";
if(empty($start))return "";
if(empty($end))return "";
$pos1 = 0;
for($i=0; $i<$start_num; $i++)
{
$pos1 = strpos($str, $start, $pos1);
if($pos1===false)
{
return "";
}
$pos1 = $pos1 + strlen($start);
}
$pos2 = $pos1;
for($i=0; $i<$end_num; $i++)
{
$pos2 = strpos($str, $end, $pos2 + 1);
if($pos2===false)
{
return "";
}
}
return substr($str, $pos1, $pos2 - $pos1);
}
$data = '<a href="http://www.csdn.net" target="_blank">中国程序员网</a><a href="http://www.msdn.com" target="_blank">外国程序员网</a><a href="http://www.mistruster.com" target="_blank">Mistruster</a>...';
echo getValue($data, '<a href="', '"');
echo "<br>\n";
echo getValue($data, '<a href="', '"', 2);
echo "<br>\n";
echo getValue($data, '<a href="', '"', 3);
//...