1function nl2br (str, is_xhtml) {
2 // http://kevin.vanzonneveld.net
3 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
4 // + improved by: Philip Peterson
5 // + improved by: Onno Marsman
6 // + improved by: Atli Þór
7 // + bugfixed by: Onno Marsman
8 // + input by: Brett Zamir (http://brett-zamir.me)
9 // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
10 // + improved by: Brett Zamir (http://brett-zamir.me)
11 // + improved by: Maximusya
12 // * example 1: nl2br('Kevin\nvan\nZonneveld');
13 // * returns 1: 'Kevin<br />\nvan<br />\nZonneveld'
14 // * example 2: nl2br("\nOne\nTwo\n\nThree\n", false);
15 // * returns 2: '<br>\nOne<br>\nTwo<br>\n<br>\nThree<br>\n'
16 // * example 3: nl2br("\nOne\nTwo\n\nThree\n", true);
17 // * returns 3: '<br />\nOne<br />\nTwo<br />\n<br />\nThree<br />\n'
18 var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br ' + '/>' : '<br>'; // Adjust comment to avoid issue on phpjs.org display
19
20 return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
21}
22
1function nl2br (str, is_xhtml) {
2 if (typeof str === 'undefined' || str === null) {
3 return '';
4 }
5 var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
6 return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
7}