这个正则表达式怎么写?

PHP编程者 2010-12-06 01:38:27
我想写一个正则匹配出这个网址:http://www.360buy.com/allSort.aspx中所有的小分类名称和ID(如:1713-3258-000),我是这样匹配的:$preg5 = "/<em><a\shref='\/([^<>]+)\/([\d-?]+)\.html'>([^<>]+?)<\/a><\/em>/";但这样只能匹配出图书里面小分类,其它的匹配不出,该怎么写这个正则呢?
...全文
142 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
PHP编程者 2010-12-08
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 heyc1998 的回复:]

PHP code

$url="http://www.360buy.com/allSort.aspx";
$content=preg_replace("/>\s+</","><",str_replace(array("\r","\n"),'',file_get_contents($url)));
preg_match_all("/<em><a\shref=[\"'][\/]?[^\/]+\/(……
[/Quote]ok了,兄弟,啥也不说了,太感谢了,有机会请你喝酒。。。。。
在-云端 2010-12-08
  • 打赏
  • 举报
回复

$url="http://www.360buy.com/allSort.aspx";
$content=preg_replace("/>\s+</","><",str_replace(array("\r","\n"),'',file_get_contents($url)));
preg_match_all("/<em><a\shref=[\"'][\/]?[^\/]+\/([-\d]+?)\.html[\"']>([^<>]+?)<\/a><\/em>/",$content,$match);
print_r($match);


之前粗心了!少考虑了情况!
现在应该没问题!
PHP编程者 2010-12-08
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 heyc1998 的回复:]

上个星期的还没弄完啊...

PHP code

$url="http://www.360buy.com/allSort.aspx";
$content=preg_replace("/>\s+</","><",str_replace(array("\r","\n"),'',file_get_contents($url)));
preg_match_all("/<em><a\shref=\"……
[/Quote]兄弟,能帮我改改吗,就差图书类匹配不出来了,你自己测试下看看,我不知道怎么改啊
PHP编程者 2010-12-07
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 heyc1998 的回复:]

上个星期的还没弄完啊...

PHP code

$url="http://www.360buy.com/allSort.aspx";
$content=preg_replace("/>\s+</","><",str_replace(array("\r","\n"),'',file_get_contents($url)));
preg_match_all("/<em><a\shref=\"……
[/Quote]图书类没有匹配出来啊
PHP编程者 2010-12-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 heyc1998 的回复:]

上个星期的还没弄完啊...

PHP code

$url="http://www.360buy.com/allSort.aspx";
$content=preg_replace("/>\s+</","><",str_replace(array("\r","\n"),'',file_get_contents($url)));
preg_match_all("/<em><a\shref=\"……
[/Quote]是啊,问题多多啊,弄得头晕脑胀的
在-云端 2010-12-06
  • 打赏
  • 举报
回复
上个星期的还没弄完啊...


$url="http://www.360buy.com/allSort.aspx";
$content=preg_replace("/>\s+</","><",str_replace(array("\r","\n"),'',file_get_contents($url)));
preg_match_all("/<em><a\shref=\"\/?products\/([-\d]+?)\.html\">([^<>]+?)<\/a><\/em>/",$content,$match);
print_r($match);


在-云端 2010-12-06
  • 打赏
  • 举报
回复
~~

4,250

社区成员

发帖
与我相关
我的任务
社区描述
国内外优秀PHP框架讨论学习
社区管理员
  • Framework
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧