tags:

views:

1519

answers:

1

Exact duplicate: Read line break in a string with javascript


Does anyone know how I can read the line break from a value with javascript and replace all the line breank with br tag?

Example:

A Variable passed from php as below:

  "This is man.

     Man like dog.
     Man like to drink.

     Man is the king."

I would like my result to look something like this after the Javascript convert it...

  "This is man<br /><br />Man like dog.<br />Man like to drink.<br /><br />Man is the king.";
+2  A: 
str = str.replace(/\n/g, '<br />');
eyelidlessness