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


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

Share This Post

Related Articles

© 2017 Sumit Bansal. All rights reserved. Site Admin · Entries RSS · Comments RSS
Powered by WordPress · Designed by Theme Junkie