English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP nl2Usage and examples of br() function

    PHP String Manual

    nl2The br() function is used to insert an HTML newline tag before all new lines in the string.

Syntax

string nl2br ( string $string [, bool $is_xhtml = true ] )

Definition and usage

Insert '<br />' or '<br>' and return.

Return value

It returns the modified string.

Parameter

Serial numberParameters and descriptions
1

string

Input string.

2

is_xhtml

Whether to use XHTML compatible newline characters.

Online example

Try the following example, insert a newline character (<br /):

<?php
   echo nl2br("oldtoolbag.com.\nAnother line."); 
?>
Test to see‹/›

Output result

oldtoolbag.com
Another line.

View the source code, the result is as follows:

oldtoolbag.com<br />
Another line.

PHP String Manual