Home Tutorial Php Examples PHP line break, PHP nl2br() function

 
 

PHP line break, PHP nl2br() function
Posted on: August 31, 2009 at 12:00 AM
Advertisement
In this tutorial we will show you how you can add the line break in your php program. We will use PHP nl2br() function to add the line break in PHP program.

The PHP Line break example & code

If you are developing the application to allow the user to enter the values in the text field and then display the same value on the website. If user enters the <enter key> to add the line break in the text field and saves the data. If you the display the same data on html page then it won't be displayed in the different paragraph. Instead all the text will displayed without any line break.

You can use the nl2br() function to add the line break in the text. The nl2br() function adds the <br> tag if it finds the carriage return (\n) in the text. If you text is long and at many places carriage return is present, even then the nl2br() tag will replace all the occurrence of the carriage return with <br> tag.

Here is the syntax of the nl2br() tag:

<?php

$myString
="Welcome to the PHP programming.\n\nHere you will learn PHP in detail";
echo nl2br($myString);

?>

Output generated by the program:

The nl2br() function will add two <br> tags as shown below:

Welcome to the PHP programming.<br /> <br /> Here you will learn PHP in detail

So, now you can use the nl2br() function to add the line break while displaying the data on webpage.

 

 

Advertisement

Related Tags for PHP line break, PHP nl2br() function:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 31, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com