这个正则怎么写? 要提取一个网页下面的部分:href="http://www.sdfg.com/brands/655-2182.html"。其中655-2182的数字部分是可变的,要求:匹配上面的所有部分,但只返回2182所在的部分 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 preg_match_all('#href="http://www.sdfg.com/brands/(\d+)-(\d+).html"#', 'href="http://www.sdfg.com/brands/655-2182.html"', $m);print_r($m[2]);//print_r($m[1]); 最好用preg_match()函数写,楼上的同学只是从http://www.sdfg.com/brands/655-2182.html中提取,其实http://www.sdfg.com/brands/655-2182.html只是整个网页源码中的一部分,我是要从整个网页源码中提取 preg_match_all('#href="http://www.sdfg.com/brands/(\d+)-(\d+).html"#', 'href="http://www.sdfg.com/brands/655-2182.html"', $m);print_r($m[2]);//print_r($m[1]); 非得用正则?把前面的 href="http://www.sdfg.com/brands/ 和后面的 .html" 截去剩下655-2182,- 字符分隔,第二部分就是你想要内容。如655-2182长度固定就更好办。 看来是我表述的有问题,这次多发点代码,就是从下面的码中匹配出href="http://www.sdfg.com/brands/655-2182.html"这句中的2182部分的值,请各位再给指点下该怎么写,先先谢了。 id=mycart-amount>0</B>件</A> <DIV class=hide id=o-mycart-list> <DIV id=mycart-list></DIV></DIV></LI> <LI class=fore2><A href="http://jd2008.360buy.com/purchase/ShoppingCart.aspx">去结算</A> </LI></UL><SPAN class=clr></SPAN></DIV></DIV><SCRIPT type=text/javascript> (function(){var navigations=[{e:"computer",c:"电脑办公"},{e:"electronic",c:"家用电器"},{e:"digital",c:"手机数码"},{e:"home",c:"家居生活"},{e:"clothing",c:"服饰鞋帽"},{e:"beauty",c:"个护化妆"},{e:"watch",c:"钟表首饰"},{e:"book",c:"图书"},{e:"sports",c:"运动健康"},{e:"baby",c:"母婴玩具"},{e:"food",c:"食品饮料"}];$.each(navigations,function(i){if (navigations[i]["e"]==document.body.id){var nlink=(document.body.id=="book")?"<a href='http://book.360buy.com/'>图书</a>":"<a href='http://www.360buy.com/"+ navigations[i]["e"] +".html'>"+ navigations[i]["c"] +"</a>";$("#nav-extra").before("<div class='curr'>"+ nlink +"</div>");}});})();$(".allsort").hoverForIE6({current:"allsorthover",delay:200});$(".allsort .item").hoverForIE6({delay:150});</SCRIPT><DIV class=w><DIV class=crumb><A href="http://www.360buy.com/">首页</A> > <A href="http://www.sdfg.com/digital.html">手机数码</A> > <A href="http://www.sdfg.com/products/652-653-000.html">手机通讯</A> > <A href="http://www.sdfg.com/products/652-653-655.html">手机</A> > <A href="http://www.sdfg.com/brands/655-2182.html">LG</A> > <A href="http://www.sdfg.com/product/204811.html">LGGD580</A> </DIV></DIV><!--crumb end--><DIV class="w main"><DIV class=right-extra><DIV id=name><H1>LG GD580 3G手机(波纹红)WCDMA/GSM<FONT id=advertiseWord style="COLOR: #ff0000"></FONT></H1></DIV><!--pname end--><DIV id=preview><DIV class=jqzoom id=spec-n1 onclick="window.open('http://www.360buy.com/bigimage.aspx?id=204811')"><IMG height=350 alt="LG GD580 3G手机(波纹红)WCDMA/GSM" mysql 日期行转列,请教各位SQL大神 求一SQL查询语句 如何求两个字段的和? 找php程序员(广州全职或兼职)3-5千元 显示ip地址的问题!! Thinkphp 项目 放到本地 路径错误 请问 [email protected] 与 nop\u0040nop\u002Epbz 之间是怎么转化的? PHP大侠们救救小第啊,我有一个问题!在线等啊~急~~ 我连最基本的提交多搞不明白了,请高手解答 请问如何保护网页上的视频只能看不能被下载? 这个搜索代码存在什么问题。。?在线等~。。 php如何可以截取汉字字符串
preg_match_all('#href="http://www.sdfg.com/brands/(\d+)-(\d+).html"#', 'href="http://www.sdfg.com/brands/655-2182.html"', $m);
print_r($m[2]);//print_r($m[1]);
print_r($m[2]);//print_r($m[1]);
把前面的 href="http://www.sdfg.com/brands/ 和后面的 .html" 截去
剩下655-2182,- 字符分隔,第二部分就是你想要内容。
如655-2182长度固定就更好办。
<DIV class=hide id=o-mycart-list>
<DIV id=mycart-list></DIV></DIV></LI>
<LI class=fore2><A
href="http://jd2008.360buy.com/purchase/ShoppingCart.aspx">去结算</A>
</LI></UL><SPAN class=clr></SPAN></DIV></DIV>
<SCRIPT type=text/javascript>
(function(){var navigations=[{e:"computer",c:"电脑办公"},{e:"electronic",c:"家用电器"},{e:"digital",c:"手机数码"},{e:"home",c:"家居生活"},{e:"clothing",c:"服饰鞋帽"},{e:"beauty",c:"个护化妆"},{e:"watch",c:"钟表首饰"},{e:"book",c:"图书"},{e:"sports",c:"运动健康"},{e:"baby",c:"母婴玩具"},{e:"food",c:"食品饮料"}];$.each(navigations,function(i){if (navigations[i]["e"]==document.body.id){var nlink=(document.body.id=="book")?"<a href='http://book.360buy.com/'>图书</a>":"<a href='http://www.360buy.com/"+ navigations[i]["e"] +".html'>"+ navigations[i]["c"] +"</a>";$("#nav-extra").before("<div class='curr'>"+ nlink +"</div>");}});})();
$(".allsort").hoverForIE6({current:"allsorthover",delay:200});
$(".allsort .item").hoverForIE6({delay:150});
</SCRIPT><DIV class=w>
<DIV class=crumb><A href="http://www.360buy.com/">首页</A> > <A
href="http://www.sdfg.com/digital.html">手机数码</A> > <A
href="http://www.sdfg.com/products/652-653-000.html">手机通讯</A> > <A
href="http://www.sdfg.com/products/652-653-655.html">手机</A> > <A
href="http://www.sdfg.com/brands/655-2182.html">LG</A> > <A
href="http://www.sdfg.com/product/204811.html">LGGD580</A> </DIV></DIV><!--crumb end-->
<DIV class="w main">
<DIV class=right-extra>
<DIV id=name>
<H1>LG GD580 3G手机(波纹红)WCDMA/GSM<FONT id=advertiseWord
style="COLOR: #ff0000"></FONT></H1></DIV><!--pname end-->
<DIV id=preview>
<DIV class=jqzoom id=spec-n1
onclick="window.open('http://www.360buy.com/bigimage.aspx?id=204811')"><IMG
height=350 alt="LG GD580 3G手机(波纹红)WCDMA/GSM"