How to remove new line from string php?

Using The removeNewline() function and remove new lines from string and replace with one empty space.

1. Code:

    <?php 
	function removeNewline($str){
		return trim(preg_replace('/\s+/', ' ', $str));
	}
  
	$str = "Soltuts.com 
is providing 
PHP 
tutorials";
	$str = removeNewline($str);
	echo($str);
    ?>

2. Example:

Input:

$str = "Soltuts.com 
is providing 
PHP 
tutorials";

Output:

Soltuts.com is providing PHP tutorials