1:要匹配的html

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<ul class="product_category">
<li class="cate expand">
<h3 class="cat-hd"><a href="/product-138893.shtml" target="_blank">铝板</a></h3>
<ul class="cat-bd">
<li><a href="/product-138896.shtml" target="_blank">7075铝板</a></li>
<li><a href="/product-138898.shtml" target="_blank">7A12T4铝板</a></li>
<li><a href="/product-138899.shtml" target="_blank">7A04铝板</a></li>
<li><a href="/product-138900.shtml" target="_blank">6082铝板</a></li>
<li><a href="/product-138901.shtml" target="_blank">6063铝板</a></li>
<li><a href="/product-138902.shtml" target="_blank">6061T651铝板</a></li>
<li><a href="/product-138903.shtml" target="_blank">6061铝板</a></li>
<li><a href="/product-138904.shtml" target="_blank">5083铝板</a></li>
<li><a href="/product-138965.shtml" target="_blank">5A02铝板</a></li>
<li><a href="/product-138905.shtml" target="_blank">5052铝板</a></li>
<li><a href="/product-138906.shtml" target="_blank">5052神户铝板</a></li>
<li><a href="/product-138907.shtml" target="_blank">2A12铝板</a></li>
<li><a href="/product-138908.shtml" target="_blank">2024铝板</a></li>
<li class="last"><a href="/product-138909.shtml" target="_blank">1060铝板</a></li>
</ul>
</li> <li class="cate">
<h3 class="cat-hd"><a href="/product-138544.shtml" target="_blank">钢材</a></h3>
</li> <li class="cate collapse">
<h3 class="cat-hd"><a href="/product-138895.shtml" target="_blank">铝管</a></h3>
<ul class="cat-bd">
<li><a href="/product-138919.shtml" target="_blank">6063铝管</a></li>
<li><a href="/product-138954.shtml" target="_blank">6061铝管</a></li>
<li><a href="/product-138952.shtml" target="_blank">5052铝管</a></li>
<li><a href="/product-138911.shtml" target="_blank">3003铝管</a></li>
<li><a href="/product-138964.shtml" target="_blank">2A12铝管</a></li>
<li class="last"><a href="/product-138960.shtml" target="_blank">1060铝管</a></li>
</ul>
</li> <li class="cate collapse">
<h3 class="cat-hd"><a href="/product-138894.shtml" target="_blank">铝棒</a></h3>
<ul class="cat-bd">
<li><a href="/product-225433.shtml" target="_blank">6061铝棒</a></li>
<li><a href="/product-138942.shtml" target="_blank">7A04铝棒</a></li>
<li><a href="/product-138967.shtml" target="_blank">6082铝棒</a></li>
<li><a href="/product-138966.shtml" target="_blank">6063铝棒</a></li>
<li><a href="/product-138920.shtml" target="_blank">5083铝棒</a></li>
<li class="last"><a href="/product-138912.shtml" target="_blank">2a12铝棒</a></li>
</ul>
</li> <li class="cate">
<h3 class="cat-hd"><a href="/product-138544.shtml" target="_blank">铝方</a></h3>
</li>
</ul> </body>
</html>

html

2:正则

 $cateReg = '/class="cate\s*\S*?">([\S\s*]+?)[^>]<\/li>/';

正则

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

05-11 20:04