Skip to content
Mike Byrne edited this page Mar 14, 2023 · 1 revision

description

Introduced 3.1.0

This function is similar to PHP's nl2br(), inserts HTML line breaks (<br>) before all newlines in a string

requires

  • nothing

parameters

  • str - required - text string to insert HTML line breaks into
  • replaceMode - optional - boolean - defaults to true - replace new line characters with <br>, if set to false, <br> are inserted and new line characters are left in the string

returns

  • text string with HTML line breaks inserted

example usage:

let text = `hello

world`;
text = nl2br(text); // 'hello<br><br>world'

With replaceMode set to false:

let text = `hello

world`;
text = nl2br(text, false); // 'hello<br>\n<br>\nworld'