I'm trying to temporarily replace all linebreaks with two whitespaces and after some function on the string revert it back from two whitespaces to a linebreak.
But it doesn't work. It won't restore the linebreaks.
This is what I do:
First replace all duplicate whitespaces with a single one.
$text = preg_replace( '/\s+/', ' ',$text );
Replace linebreaks with two whitespaces.
$text = str_replace( array( '\r', '\r\n', '\n'), ' ', $text );
Run some functions..
Restore the linebreaks
$text = str_replace( ' ', '\n', $text );
As far as I can see it replaces the linebreaks with a single whitespace. Not like defined two of them. What happens? Using \s\s
doesn't change things.
Tested some things:
str_replace
(step 2) fails to detect the linebreaks only AFTER I used preg_replace
to replace duplicate whitespaces (step 1).
Without step 1 it works.