开发者

php preg_replace except

开发者 https://www.devze.com 2023-03-25 09:40 出处:网络
There are many paragraph in one test. <div class=\"text\">...</div> <div class=\"content\">...</div>

There are many paragraph in one test.

<div class="text">...</div>
<div class="content">...</div>
<div class="aa bb">...</div>
<div class="aa cc">...</div>
<div class="aa dd">...</div>
<div class="aa ee">...</div>
<div class="aa ff">...</div>
...// more type of class="aa .*"

I want remove all the div class="aa" but except div class="aa dd", how to do this job? Thanks.

$html = preg_replace('/<div(.*?)class="aa(.*?)">([\s\S]*?)<\/div>/', '', $html);
// this will remove all the div include class 'aa', but I need rem开发者_如何转开发ain class 'aa dd'


echo preg_replace('~<div class="aa (?!dd).+?">.+?</div>~', "", $html);
0

精彩评论

暂无评论...
验证码 换一张
取 消