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>”);

Bansal Sumit

To seek challenging roles and to achieve excellence in the field of Open Source Web Technology with a profound spirit of commitment and dedication.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.