如何在php中匹配\ n \ r和preg_replace

时间:2016-10-30 07:52:01

标签: php regex

我想删除html中的空段落:

<p>
</p>

使用/<p>\n\r<\/p>/无法与此匹配 使用/<p>.{0,2}<\/p>/时有效,为什么?

1 个答案:

答案 0 :(得分:3)

当您需要换行时,\r(返回)会出现在\n(新)之前,因此在您的表达式中,您应该使用\r\n