PHP

PHP Nl2br() Function Example Tutorial

This article will provide some of the most important example nl2br in PHP. Here you will learn PHP nl2br example. this example will help you PHP nl2br() function example. you'll learn PHP convert nl2br. Let's see bellow example PHP nl2br replace n to br.

  • 4.5/5.0
  • Last updated 05 September, 2022
  • By Admin

nl2br() function will replace \n into newline. so let's see syntax and example

Syntax

nl2br() function will take two argument. first as string and it's required. second as A boolean value that indicates whether or not to use xhtml compatible line breaks and it's optional.

nl2br(string,xhtml)
Example

index.php

<?php
$desc = "Line one \n Line two \n Line three \n Live four \n Line five ";
echo nl2br($desc);
?>

Output

I hope it can help you...

Line one
Line two
Line three
Live four
Line five

I hope it can help you...