w3resource logo


PHP nl2br() function

PHP : nl2br() function

rating has average rating 5 out of 10. Total 1 users rated.

<<PreviousNext>>

Description

The nl2br() function is used to insert HTML line breaks ('<br />') before all newlines (\n) in a string.

Version

(PHP 4 and above)

Syntax

nl2br(input_string)

Parameter

Name Description Required /
Optional
Type
input_string The input string Required String
is_xhtml Whether XHTML compatible line breaks will be used or not. Optional Boolean

Return value

Returns the altered string.

Value Type : String.

Pictorial Presentation

php-string-nl2br()

Example :

<?php
echo nl2br("w3resource \n. \ncom");
?>

Output :

w3resource
.
com

View the example in the browser

See also

PHP Function Reference

<<PreviousNext>>