3v4l.org

run code in 300+ PHP versions simultaneously
<?php $textbefore = '<a href="test">text</a> 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:
46.79 ms | 402 KiB | 5 Q