<div class="Wrapper">
<div class="colImg">
<a href="http://store.shopping.yahoo.co.jp/matsunami/fcdm3.html"></a>
</div>
<div class="wrCol cf">
<div class="colText">
</div>
<div class="colPrice">
<p class="price"><em>4,603</em></p>
</div>
<div class="colStore">
</div>
</div>
<div class="itemMatch"><a href="http://topics.shopping.yahoo.co.jp/notice/archives/post_8.html">123</a></div>
</div>
我想要获取
<div class="Wrapper"></div>
里面的整个内容(包含了6个div,也可能是7个div,所以包含的div个数可能不定),即:
<div class="colImg">
<a href="http://store.shopping.yahoo.co.jp/matsunami/fcdm3.html"></a>
</div>
<div class="wrCol cf">
<div class="colText">
</div>
<div class="colPrice">
<p class="price"><em>4,603</em></p>
</div>
<div class="colStore">
</div>
</div>
<div class="itemMatch"><a href="http://topics.shopping.yahoo.co.jp/notice/archives/post_8.html">123</a></div>
如何用preg_match_all获取如上字符串,或者用其他方法来实现?
preg_match_all($reg,$str.$data)
$reg 为你匹配的正则表达式
$str 为要匹配的字符串
$data 为匹配到的数组
首先$str = file_get_contents($filename)将文件读入字符串
然后正则$reg = '/^
正则对嵌套的截取不是很好操作,建议是找前后特殊字符substr来搞好点。。
或者用simple_html_dom,参考:http://www.jb51.net/article/39526.htm
觉得这种问题,先可以去手册里看看,还不懂的话,再在百度、google搜索看看,应该有好多这方面的信息,如果还不会的话再来问。
如果要提取html中的内容话最好用simple_tml_dom,这个类的用法很想jQuery。建议你用这个