开发者社区 问答 正文

php中如何用preg_match_all匹配字符串呢?

 <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获取如上字符串,或者用其他方法来实现?

展开
收起
小旋风柴进 2016-03-06 15:04:41 2715 分享
分享
版权
举报
1 条回答
写回答
取消 提交回答
  • preg_match_all($reg,$str.$data)
    $reg 为你匹配的正则表达式
    $str 为要匹配的字符串
    $data 为匹配到的数组
    首先$str = file_get_contents($filename)将文件读入字符串
    然后正则`$reg = '/^
    (.*)

    $/';`
    然后preg_match_all($reg,$str,$data)
    打印下$data看看 这种多层嵌套不是太容易匹配 多改改正则即可
    2019-07-17 18:54:39 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
问答分类:
PHP
问答标签:
问答地址:
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等