How to Replace Newline with Space Using PHP

Sometimes you need to replace newline to space or any other format (i.e:- \r\n). This is done by copying and pasting the content. To resolve this problem I use the given blow code.

$remove_character = array(“\n”, “\r\n”, “\r”);

$str = str_replace($remove_character , ‘ ‘, $str);

The above code will work fine to remove the new line from the article. You can add more into this array for example

$remove_character = array(“\n”, “\r\n”, “\r”, “<p>”, “</p>”);

Share This Post

Post Comment