A php variable contains the following string:
text
text2
- item1
- item2
$no_newlines = str_replace("\r", '', str_replace("\n", '', $str_with_newlines));
Replace a string :
$str = str_replace("\n", '', $str);
u using also like, (%n, %t, All Special characters, numbers, char,. etc)
which means any thing u can replace in a string.
To remove new lines from string, follow the below code
$newstring = preg_replace("/[\n\r]/","",$subject);
you can pass an array of strings to str_replace
, so you can do all in a single statement:
$content = str_replace(["\r\n", "\n", "\r"], "", $content);