sâmbătă, 4 decembrie 2010

How to remove newline character in PHP

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.

U can try the code below $str = "Haha\nHehe\n";$x = preg_replace("/\n|\r/", " ", $str);// if preg found new line, it will replace and store in array index 1if(isset($x[1]) { echo $x[1];}Output will be:- Haha Hehe

Notice that the newline now been replaced by white space


View the original article here

Niciun comentariu:

Trimiteți un comentariu