3v4l.org

run code in 300+ PHP versions simultaneously
<?php $textbefore = "text has newlines in wo\nrds and normal newlines \n bewtween words and again in wo\nrds"; $textafter = preg_replace( "/(?<=\S)\n|\n(?=\S)/", '', $textbefore); var_dump( $textafter);

preferences:
36.96 ms | 402 KiB | 5 Q