How to remove new lines from a string and replace them with one empty space in PHP

1 Answer

0 votes
$s = "php \njava   \npython\n";

$s = trim(preg_replace('/\s+/', ' ', $s));

echo $s;


/*
run:

php java python

*/

 



answered Mar 8, 2019 by avibootz
...