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:
How to install apache, php, mysql with macport in Mac OS X
Symfony: How to escape hash # character in yaml
WordPress: How to upload image using script?
Symfony 1.4: How to sort foreign key record?
Virtue Theme: How to enable slider in shop page?
Speed Up and Save Your Website Bandwidth with GZip Compression
How to extract img tag attributes using PHP?
Symfony 1.4 - Customize Admin Generator listing to show data from foreign tables
Share this with your friends:-