To remove the new lines from a string and replace with a single space, we can use the
preg_replace() functions by passing the regex
/\s+/ as an argument in PHP.
Here is an example:
<?php $string = " You can see me in a single line "; $string = trim(preg_replace('/\s+/', ' ', $string)); echo $string; ?>
You can see me in a single line