how to remove "\n" in string?
I used 3 method bellow ,seams that only the "\s+" works , but I only want to remove \n,not all space ,how to do the job?
need help, this question had puzzled me for a long time.
$str="<p>
hello<br>
world
</p>";
//$str=str_replace("\n","",$str);
$str=preg_replace("@\n@","",$str);
//$str=preg_replace("@\s+@"," ",$str);
echo $str;
This should also do the trick.
$str=str_replace("\r\n","",$str);
$string = trim(preg_replace('/\s\s+/', ' ', $string));
The above code will replace multiple spaces and newlines with a single space.
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