删除换行符和空格php [复制]

This question already has an answer here:

I have a string:

$str = '
            This Like a Somthing awesome text with 
   goods:Fb,Teleg,Top,Prods.fm,Ad-...
';

How I can remove spaces and line breaks? I want get this:

$str = 'This Like a Somthing awesome text with goods:Fb,Teleg,Top,Prods.fm,Ad-...';

A tried use:

trim($str);

But get same result.

</div>

You can use a combination of trim to remove leading and trailing whitespace, and preg_replace to replace all newlines and their surrounding spaces internal to the string with a single space:

$str = preg_replace('/\s*\R\s*/', ' ', trim($str));
echo $str;

Note in the above regex \R matches any newline (, ) character.

Output:

This Like a Somthing awesome text with goods:Fb,Teleg,Top,Prods.fm,Ad-...

Demo on 3v4l.org