102
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 (rn, nr, 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 TutorAspire By using 'nl2br()' function: Hello . PHP. TutorAspire
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