如何更改此正则表达式,以便它选择具有多个 img 的段落元素


how to change this regex so it selects paragraphs elements with more than one img

这是一个后续问题:区分 Wordpress 中包装图像的 P 标签和包装文本节点的 P 标签?

我想修改解决方案:

 function my_content_filter($content) {
   return preg_replace('|<p>(<img[^<]*)</p>|i', '<p class="foo">${1}</p>', $content);
 }
 add_filter('the_content', 'my_content_filter');`

这样它就可以用于具有多个<img>元素的<p>

试试这是否适合你。

function my_content_filter($content) {
return preg_replace('|<p>((<img[^>]*>)*)<'/p>|i', '<p class="foo">${1}</p>', $content);
}
add_filter('the_content', 'my_content_filter');`