PHP

PHP Menu

PHP

nl2br() Function - Definition, Syntax, Parameters, Examples

Definition

The nl2br() function inserts HTML line breaks (<br> or <br />) in front of each newline (\n) in a string.

Syntax

nl2br(string, xhtml)

Parameters

Parameter Description
string Required. Specifies the string to check.
xhtml Optional. A boolean value that indicates whether or not to use XHTML compatible line breaks:
true- Default. Inserts <br />
false - Inserts <br>

Example

<?php
echo nl2br("First line.\nSecond line.");

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods