<div class="post-content">
php怎么统计 post-content 内的img数量,并且输出数量,如上面代码,img数量是3
回复内容:
<div class="post-content">
php怎么统计 post-content 内的img数量,并且输出数量,如上面代码,img数量是3
用preg_match_all
正则匹配行么?
$text = '<div class="post-content"></div>';$preg = "/(\ <p class="answer fmt"> <p>用正则来解析 html 是不推荐的做法,见 http://stackoverflow.com<strong>2本文来源gaodaima#com搞(代@码$网6</strong><pre>搞gaodaima代码
/questions/17… ,最好使用一些 PHP 的 dom 解析库。
- http://simplehtmldom.sourceforge.net/
- http://stackoverflow.com/questions/29…
- http://stackoverflow.com/questions/35…
为什么不用jQuery呢
$(‘.post-content img’).length();