Sia
Sia

Reputation: 45

How can I match \n\r with preg_replace in php

I want to remove the empty paragraphs in html:

<p>
</p>

use /<p>\n\r<\/p>/ can't match this while use /<p>.{0,2}<\/p>/ works, why?

Upvotes: 3

Views: 46

Answers (1)

Yury Fedorov
Yury Fedorov

Reputation: 14928

When you need a new line, \r (return) comes before \n (new), so in your expression you should use \r\n.

Upvotes: 3

Related Questions