码迷,mamicode.com
首页 > Web开发 > 详细

匹配一级分类和二级分类 名字和url 里面有玄机

时间:2015-04-14 00:16:55      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

1:要匹配的html

技术分享
 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
 5 <title>无标题文档</title>
 6 </head>
 7 <body>
 8 <ul class="product_category">
 9     <li class="cate expand">
10         <h3 class="cat-hd"><a href="/product-138893.shtml" target="_blank">铝板</a></h3>
11         <ul class="cat-bd">
12             <li><a href="/product-138896.shtml" target="_blank">7075铝板</a></li>
13             <li><a href="/product-138898.shtml" target="_blank">7A12T4铝板</a></li>
14             <li><a href="/product-138899.shtml" target="_blank">7A04铝板</a></li>
15             <li><a href="/product-138900.shtml" target="_blank">6082铝板</a></li>
16             <li><a href="/product-138901.shtml" target="_blank">6063铝板</a></li>
17             <li><a href="/product-138902.shtml" target="_blank">6061T651铝板</a></li>
18             <li><a href="/product-138903.shtml" target="_blank">6061铝板</a></li>
19             <li><a href="/product-138904.shtml" target="_blank">5083铝板</a></li>
20             <li><a href="/product-138965.shtml" target="_blank">5A02铝板</a></li>
21             <li><a href="/product-138905.shtml" target="_blank">5052铝板</a></li>
22             <li><a href="/product-138906.shtml" target="_blank">5052神户铝板</a></li>
23             <li><a href="/product-138907.shtml" target="_blank">2A12铝板</a></li>
24             <li><a href="/product-138908.shtml" target="_blank">2024铝板</a></li>
25             <li class="last"><a href="/product-138909.shtml" target="_blank">1060铝板</a></li>
26         </ul>
27     </li>
28     
29     <li class="cate">
30         <h3 class="cat-hd"><a href="/product-138544.shtml" target="_blank">钢材</a></h3>
31     </li>
32     
33     <li class="cate collapse">
34         <h3 class="cat-hd"><a href="/product-138895.shtml" target="_blank">铝管</a></h3>
35         <ul class="cat-bd">
36             <li><a href="/product-138919.shtml" target="_blank">6063铝管</a></li>
37             <li><a href="/product-138954.shtml" target="_blank">6061铝管</a></li>
38             <li><a href="/product-138952.shtml" target="_blank">5052铝管</a></li>
39             <li><a href="/product-138911.shtml" target="_blank">3003铝管</a></li>
40             <li><a href="/product-138964.shtml" target="_blank">2A12铝管</a></li>
41             <li class="last"><a href="/product-138960.shtml" target="_blank">1060铝管</a></li>
42         </ul>
43     </li>
44     
45     <li class="cate collapse">
46         <h3 class="cat-hd"><a href="/product-138894.shtml" target="_blank">铝棒</a></h3>
47         <ul class="cat-bd">
48             <li><a href="/product-225433.shtml" target="_blank">6061铝棒</a></li>
49             <li><a href="/product-138942.shtml" target="_blank">7A04铝棒</a></li>
50             <li><a href="/product-138967.shtml" target="_blank">6082铝棒</a></li>
51             <li><a href="/product-138966.shtml" target="_blank">6063铝棒</a></li>
52             <li><a href="/product-138920.shtml" target="_blank">5083铝棒</a></li>
53             <li class="last"><a href="/product-138912.shtml" target="_blank">2a12铝棒</a></li>
54         </ul>
55     </li>
56     
57     <li class="cate">
58         <h3 class="cat-hd"><a href="/product-138544.shtml" target="_blank">铝方</a></h3>
59     </li>
60 </ul>
61 
62 
63 </body>
64 </html>
html

 

2:正则

技术分享
1 $cateReg = ‘/class="cate\s*\S*?">([\S\s*]+?)[^>]<\/li>/‘;
正则

要测试的在线工具 : http://regexpal.isbadguy.com/

匹配一级分类和二级分类 名字和url 里面有玄机

标签:

原文地址:http://www.cnblogs.com/qzjpkfj/p/4423509.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!