fish man
fish man

Reputation: 2700

php preg_replace except

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 remain class 'aa dd'

Upvotes: 0

Views: 1306

Answers (1)

user187291
user187291

Reputation: 53940

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

Upvotes: 2

Related Questions