Replace newlines with BR (platform safe)


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function nl2br(text){
  2. text = escape(text);
  3. if(text.indexOf('%0D%0A') > -1){
  4. re_nlchar = /%0D%0A/g ;
  5. }else if(text.indexOf('%0A') > -1){
  6. re_nlchar = /%0A/g ;
  7. }else if(text.indexOf('%0D') > -1){
  8. re_nlchar = /%0D/g ;
  9. }
  10. return unescape( text.replace(re_nlchar,'<br />') );
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.