简体   繁体   English

在PHP中删除多个/ n

[英]Delete multiple /n in php

I'm working on a old database, and i'm trying to clear the multiple /n on the text fields. 我正在使用旧的数据库,并且试图清除文本字段中的多个/ n。

I have found this code : 我找到了以下代码:

   $newphrase = preg_replace("#\n+#", "\n", $newphrase);

It's works, but I want to replace /n only when there is more than 3 /n, not two. 它是可行的,但是我只想在/ n大于3而不是两个的情况下替换/ n。

So, my goal is to transform : 所以,我的目标是改变:

Hello n/ guys /n /n how are /n /n /n you ?

into 进入

Hello n/ guys /n /n how are /n /n you ?

Do you have any idea ? 你有什么主意吗 ?

$newphrase = preg_replace("#(\n ?){3,}#", "\n\n", $newphrase);

如果您的意思是/n而不是\\n (换行符),请执行以下操作:

$newphrase = preg_replace("/(?:\/n\x20?){3,}/", "\/n\x20\/n\x20", $newphrase);

Replacing 3 or more blank lines with 1 blank line - 用1条空行替换3条或更多空行-

Find: 找:
\\n(?:[^\\S\\n]*\\n){2,}
Replace: 更换:
\\n

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM