我想匹配出http://www.so.com/s?q=csdn&pn=7&j=0里每个搜索结果的url,用下面的正则匹配出的结果为空,错在哪里呢?
$c1 = "/<h3 class=\"res-title (?:\-nowrap)?\">\s*<a target=\"_blank\" data-m=\"(?:.*)\" data-pos\"(?:\d+)\" data-e=\"(?:\d+)\" data-st=\"(?:\d+)\" href=\"(.*)\">(?:.*)<\/a>\s*<\/h3>/Uis";
$content= get_content('http://www.so.com/s?q=csdn&pn=7&j=0');
preg_match_all($c1,$content,$arr1);
print_r($arr1);正则表达式php匹配
$c1 = "/<h3 class=\"res-title (?:\-nowrap)?\">\s*<a target=\"_blank\" data-m=\"(?:.*)\" data-pos\"(?:\d+)\" data-e=\"(?:\d+)\" data-st=\"(?:\d+)\" href=\"(.*)\">(?:.*)<\/a>\s*<\/h3>/Uis";
$content= get_content('http://www.so.com/s?q=csdn&pn=7&j=0');
preg_match_all($c1,$content,$arr1);
print_r($arr1);正则表达式php匹配
解决方案 »
- php字符串截取
- 请问有没有好用的绿色支持php的webserver?
- 关于php 读取xml的问题
- phpmailer发送html邮件
- 如何在用PHP生成的excle表里插入图片?
- 请教关于数据库
- 大侠看看这个网页的加密
- win2003服务器+iis+php exec无法调用php外部命令
- win2000+IIS5+php4.22中如何避免在无某一页时显示“Warning: Failed opening 'E:\web\aaa.com\..”
- 我的mysql不能用了!快来救救我!!谢谢谢谢!!!!!!!!!!
- Zend Studio为什么写错误的代码不报错
- 在ubuntu下安装php版本问题
$urls = 'http://www.so.com/s?q=csdn&pn=7&j=0';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$urls);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
$c1 = "/<li class=\"res-list\">(.*?)<a href=\"(.*?)\">(.*?)<\/a>(.*?)<\/li>/is";
preg_match_all($c1,$content,$arr1);
foreach($arr1[0] as $part){
$c2 = "/href=('|\")(.*?)(?1)\s+/is";
preg_match_all($c2,$part,$arr2);
echo $arr2[2][0].'<br />';
}