Sia Sia - 1 month ago 5
PHP Question

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?

Answer

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

Comments