Para realizar esto mismo en Javascript podemos usar la siguiente función:
function nl2br(str, is_xhtml) {
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '< br />' : '< br>'; // Eliminar el espacio antes del br
return (str + '')
.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
}
Fuente:
http://phpjs.org/functions/nl2br/
No hay comentarios:
Publicar un comentario