is there any php method to remove new line char from string?
$str ="
Hi
there
";
my string contains a new line char between 'Hi' and 'there' i want output as a "Hi there".I don't want to use regular expression.
In Python strings, the backslash "\" is a special character, also called the "escape" character. It is used in representing certain whitespace characters: "\t" is a tab, "\n" is a newline, and "\r" is a carriage return.
Escape the HTML, and then replace \n with <br> .
This is a bit confusing
is there any php method to remove new line char from string?
It looks like you actually want them replaced with a space.
$str = str_replace(array("\r\n", "\n", "\r"), ' ', $str);
Assuming the replacing goes from left to right, this should suit Windows text files.
The first grouping is to match Windows newlines which use both \r and \n.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With