I have a variable ($myClass[0]->comment;) that has carriage return in it. I want to replace all the carriage return in that variable with “\n”
how can I do that.
below may help a bit
$myClass[0]->comment;
Here is some output
<?php
$test = explode(chr(13),$myClass[0]->comment );
var_dump($test);
?>
OUTPUT
array
0 => string '12' (length=2)
1 => string '
' (length=1)
2 => string '
22' (length=3)
All I want is \n instead of carriage return.
If you want to replace each CR (\r) with LF (\n), do this
If you want a literal \n, do this
It’s more likely you want to replace CR LF, in which simply search for
"\r\n"instead.