Javatpoint Logo
Javatpoint Logo

PHP String nl2br() Function

PHP string nl2br() is predefine function which is used to insert HTML line break before all newlines in a string. It returns string with <br \> or <br> before all newlines (\r\n, \n\r, \n and \r).

Syntax:

Parameter Description Required/Optional
String Specify input string required
xhtml Boolean value, whether to use XHTML compatible line breaks or not. .True- Default. Inserts <br /> .False -Insert <br> optional

Example 1

Note: Generating valid HTML markup by using 'is_xhtml' parameter.

Output:

Your string is: Hello .\ n PHP. \ n Javatpoint
By using 'nl2br()' function: Hello .
PHP.
Javatpoint

Example 2

Output:

Your string is: Welcome \ r\ n We are learning PHP
By using 'nl2br()' Function: 
Welcome
We are learning PHP

Example 3

Output:

By using 'nl2br()' Function:This
is
a
PHP Tutorial

Next TopicPHP String





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA