I need to remove newline character using PHP from user input, so the input will show in one line for my CSV file. I’ve tried to use nl2br and str_replace the br tag but it doesn’t work. At the end, i need to use regular expression to solve this.
To remove newline character in PHP, follow the steps below:-
Advertisements
- U can try the code below
$str = "there is new line\nin this string\n"; $x = preg_replace("/\n|\r/", " ", $str); echo $x;
- Output will be:-
there is new line in this string
Notice that the newline now been replaced by white space
Related posts:
PHP Fatal error: Class ‘DOMDocument’ not found in …
PHP: How to convert ISO character (HTMLEntities) to UTF-8?
Prestashop 1.5 - How to enable add to cart button at Home Featured Product?
Symfony: Control Model->save() function to perform INSERT or UPDATE
Symfony: PHP Fatal error: Call to a member function setData()
Composer: PHP Fatal error: Allowed memory size of ... exhausted...
How to downgrade to PHP 5.2 using MacPort
WordPress: How to upload image using script?
Share this with your friends:-