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"
"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.
source
share