How to replace all new lines of string with `<BR>` in php? -
there confusion \n , \r.
there lot's of questions in stack differences between \n , \r. in nut shell confusions/questions are:
- is \r\n equal \n\r?
- is \r\n cause 2 new lines?
- is \r cause new line in output?
- how can replace new lines
<br>
tag in php?
not strings has \r or \n explicitly. suppose have textarea , user inputs characters including enter of keyboard. no \r or \n entered new lines exist. how remove new lines?
microsoft windows / ms-dos: \r\n
acorn bbc , risc os spooled text output: \n\r
apple macintosh os 9 , earlier: \r
unix (e.g., linux), apple os x , higher: \n
replace -> nl2br
more on here
if new lines exists in textarea \n,\r or \r\n present! these control characters not outputted.
to remove them try:
$string = str_replace(array("\r\n", "\n\r", "\r", "\n"), "", $string);
Comments
Post a Comment