<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 = "/(\@@##@@)/s"; echo preg_match_all($preg, $text, $match);
用正则来解析 html 是不推荐的做法,见 http://stackoverflow.com/questions/17... ,最好使用一些 PHP 的 dom 解析库。
为什么不用jQuery呢
$('.post-content img').length();
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号