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:

  1. is \r\n equal \n\r?
  2. is \r\n cause 2 new lines?
  3. is \r cause new line in output?
  4. 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

Popular posts from this blog

c++ - Function signature as a function template parameter -

How to call a javascript function after the page loads with a chrome extension? -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -