Created
November 15, 2013 10:14
-
-
Save bjrnqprs/7482136 to your computer and use it in GitHub Desktop.
Convert new lines in given string to <br> tags.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function nl2br (str, is_xhtml) { | |
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>'; | |
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment