Remove line breaks with regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$string = 'This is a new paragraph with | |
arbitrarily inserted newlines | |
at a certain width. To keep | |
these from turning into <br>s, | |
we want to replace them the right | |
way. | |
When there is a double new-line, | |
then we know that it really is a | |
new paragraph, and it is OK to keep | |
both newlines together.'; | |
$content_without_line_breaks = preg_replace( '/(^|[^\n\r])[\r\n](?![\n\r])/', '$1 ', $string ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment