作者:____洋果子 | 来源:互联网 | 2023-07-10 23:34
Edit: The problem described below was just caused by a "feature" of my IDE, so there's actually nothing wrong with the regex. If you're interested in how to double line breaks, here's your question and answer in one neat package. :)
编辑:下面描述的问题只是由我的IDE的“功能”引起的,因此正则表达式实际上没有任何问题。如果您对如何加倍换行感兴趣,请在一个整齐的包中找到您的问题和答案。 :)
I want to change every line break in a string to be two line breaks:
我想将字符串中的每个换行符更改为两个换行符:
"this is
an example
string"
// becomes:
"this is
an example
string"
However, it needs to take Unix/Windows line endings into account. I've written the code below, but it's not behaving itself.
但是,它需要考虑Unix / Windows行结尾。我已经编写了下面的代码,但它并没有表现出来。
$output = preg_replace("/(\r?\n)/", "$1$1", $input);
But it's not working. Changing the replacement string to this...
但它不起作用。将替换字符串更改为此...
"$1 $1"
...makes it work, but then I have an unwanted space in between.
...使它工作,但我之间有一个不需要的空间。
2 个解决方案