How to Replace Newline with Space Using PHP

Sometimes you need to replace newline (i.e. \r\n) with space. While I am trying to do this in my website I wonder why str_replace function doesn’t work.

Example:

$remove = array("\n", "\r\n", "\r"); $str = str_replace($remove, ' ', $str);

While the above code is correct I found out that not all instances of my article’s content uses the PHP escape code to insert a newline.