How to double all line breaks?

Change . The problem described below was caused by the "function" of my IDE, so there is nothing wrong with the regex. If you are interested in doubling line breaks, here is your question and answer in one neat package. :)

I want to change each line break in a line to two line breaks:

"this is
an example
string"
// becomes:
"this is

an example

string"

However, it should consider Unix / Windows line endings. I wrote the code below, but it does not behave.

$output = preg_replace("/(\r?\n)/", "$1$1", $input);

But it does not work. Changing the replacement string to this ...

"$1 $1"

... makes it work, but then I have unwanted space between them.

+3
source share
2 answers

. UNIX (Ubuntu FreeBSD ). , , . .

+1

. ? ? HTML. <pre> </pre> , .

+1

Source: https://habr.com/ru/post/1705763/


All Articles