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.
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.
$str=str_replace("\n", "", $str); should do it.
"\n" represents a newline in php.
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.
To get the expected results, you'll be needing:
$str = trim(str_replace( array("\r\n","\r","\n",' '), ' ' , $str));
or with regex (which is fail safe, you can't account for all the additional spacing you may get with str_replace version):
$str = trim(preg_replace( array('/\v/','/\s\s+/'), ' ' , $str)); // 'Hi there'
Hello,
You can use below script.
$str=str_replace("\n", "", $str);
Thanks