What is the NL2BR function in PHP

nl2br

description

stringnl2br (string [, bool = true])

Returns the '
' or '' inserted before any newline character (, \ r \ n, \No\ n and).

\ r

Parameter list

The input string.

Determines whether or not to use XHTML-compatible line breaks.

Return values

Returns the changed string.

Examples Example # 1 using

nl2br ()

The example shown above produces the following output:

foo is not
bar

Example # 2 Creating valid HTML markup using the parameter

The example shown above produces the following output:

Welcome

This is my HTML document

Example # 3 Different line separators

The example shown above produces the following output:

This
is
a
string
Changelog
5.3.0version
4.0.5description The optional parameter has been added.

nl2br ()

  • is now XHTML compliant. All older versions return with '
  • ' inserted before all line breaks instead of '
    '.
  • See also
  • htmlspecialchars () - Converts special characters into HTML codes