PHP nl2br() Function
In this chapter you will learn:
- Definition for PHP nl2br() Function
- Syntax for PHP nl2br() Function
- Parameter for PHP nl2br() Function
- Return for PHP nl2br() Function
- Example - Convert new line character with br
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 j av a2 s . c o m*/
$mystr = "This is a test\nfrom java2s.com.";
$brstr = nl2br($mystr);
print $brstr;
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP nl_langinfo() Function
- Syntax for PHP nl_langinfo() Function
- Parameter for PHP nl_langinfo() Function
- nl_langinfo Constants
- Return for PHP nl_langinfo() Function
- Note for PHP nl_langinfo() Function
Home » PHP Tutorial » PHP String Functions