PHP nl2br() Function

Definition

The nl2br function inserts a HTML line break (<br/>) before all new line characters. It does not replace the line breaks which means the \n breaks are left intact.

Syntax

PHP nl2br() Function has the following syntax.

string nl2br ( string str )

Parameter

str is the string to convert.

Return

PHP nl2br() Function returns the string with new line character being converted by <br>.

Example

Convert new line character with <br>.


<?PHP/*from  w  w w .  j a va 2s.c om*/
$mystr = "This is a test\nfrom java2s.com."; 
$brstr = nl2br($mystr); 
print $brstr;
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions