ItSolutionStuff.com

PHP nl2br() Function Example Tutorial

By Hardik Savani • May 14, 2024
PHP

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.

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

Line one

Line two

Line three

Live four

Line five

I hope it can help you...

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Add Text Watermark to Image in PHP?

Read Now →

PHP implode() Function Example Tutorial

Read Now →

PHP Subtract Month from Date Example

Read Now →

How to Upgrade PHP Version from 7.4 to 8 in Ubuntu?

Read Now →

PHP Curl Delete Request Example Code

Read Now →

PHP Curl Request with Certificate (cert pem file option) Example

Read Now →

Laravel PHP json_decode without quotes Example

Read Now →

How to Remove Multiple Keys from PHP Array?

Read Now →

How to Find Day Name from Specific Date in PHP?

Read Now →

How to Remove Null Values from Array in PHP?

Read Now →