PHP nl2br() Function

PHP nl2br() Function

The nl2br() function in PHP inserts HTML line breaks before all newlines in a string.

Syntax

nl2br ( string $string [, bool $is_xhtml] )

Parameter

sting(required)- This parameter specifies the input string.

is_xhtml(optional)- This parameter states whether to use XHTML compatible line breaks or not.. The default value is true.

Return

This function returns the altered string with <br /> or <br> inserted before all newlines (\r\n, \n\r, \n and \r).

Example 1

 or 
) in front of each newline (\n) in a string. echo "\nAfter using the 'nl2br()' function...\nNew Sring: ".nl2br($str);  ?> 

Output

String: Hello
Example
and
Tutorial
After using the 'nl2br()' function... 
New Sring Hello
Example
and
Tutorial 

Example 2

 or 
) in front of each newline (\n) in a string. echo "\nAfter using the 'nl2br()' function...\nNew Sring: ".nl2br($str);  ?> 

Output

String: This
is
a
nl2br() example
After using the 'nl2br()' function...
New Sring: This
is
a
nl2br() example 

Example 3

 or 
) in front of each newline (\n) in a string. echo "\nAfter the nl2br() function...\n"; echo nl2br($str,false); // passed false will return
instead of
?>

Output

String: This is a
nl2br() example
After the nl2br() function...
This is a<;br>
nl2br() example 

Related Topics

PHP stristr() Function

PHP stristr() Function The stristr() function in PHP finds the first occurrence of a string and returns the matched substring. It is a case-insensitive function. Syntax stristr ( string $haystack , mixed $needle [, bool $before_needle ] ) Parameter haystack(required)- This parameter represents the input string. needle(required)- This parameter...

2 minutes read.

PHP array_intersect_uassoc() function

The array_intersect_uassoc () function in PHP is used to compute the intersection of arrays with the help of an additional index check, comparing indexes by a callable function. It returns an array containing...

1 minute read.

PHP array_multisort() Function

PHP array_multisort () Function The array_multisort() function in PHP sorts multiple or multi-dimensional arrays at once. Syntax array_multisort ( array &$array1 [, mixed $array1_sort_order [, mixed $array1_sort_flags [, mixed $... ]]] ) Parameter array1(required)- This parameter specified the input array to sort. array1_sort_order(optional)- This parameter specifies the order (ascending or descending)...

1 minute read.

PHP count_chars() Function

PHP count_chars() Function The count_chards() function in PHP is used to return information about characters in a string. Syntax count_chars ( string $string [, int $mode = 0 ] ) Parameter string(required)- This parameter represents the string to be checked. mode(optional)- It specifies the return modes Return This function returns one...

2 minutes read.

PHP array_merge() Function

PHP array_merge() Function The array_merger() Function in PHP merges the elements of one or more arrays wherein the values of one are appended to the end of the previous one. It returns the resulting array...

1 minute read.

PHP Do While Loop

PHP do while loop is used to execute the code at least one time because condition is checked after executing the code. Syntax: do{ //code to be executed  }while(condition); Output <?php $n=1;  do{ echo "$n<br/>";  $n++;  }while($n<=5);  ?> Output 1 2 3 4 5 ← Prev Next →...

1 minute read.

Python if-else

Python if-else The else statement is associated with if statement. An else statement executes if the conditional expression in if the statement becomes false or a Zero value. If the conditional expression...

2 minutes read.

PHP isset() function

PHP isset is used to check whether the variable is set or not.The PHP isset() function returns false if variable contains a NULL value. Syntax: isset(variable1, variable2….) Presentation of PHP isset: In...

2 minutes read.

PHP array_walk_recursive() Function

PHP array_walk_recursive() Function The array_walk_recursive () function in PHP is used to apply a user-defined callback function recursively to each element of the array. This function returns a Boolean TRUE on success or FALSE on failure. Syntax array_walk_recursive ( array &$array , callable $callback [, mixed $userdata = NULL ] ) Parameter array(required)- This array represents the...

1 minute read.

PHP metaphone() Function

PHP metaphone() Function The metaphone() function in PHP calculates the metaphone key (representing how a string sounds or pronounced) of a string. This function is used to text search and text matching or spelling...

1 minute read.

PHP strval() function

PHP strval() function The strval() function in PHP is used to get the string value for the specified variable. This function cannot be used on arrays or objects, if applied then would return only the...

1 minute read.

PHP strrchr() Function

PHP strrchr() Function The strrchr() function in PHP finds the last occurrence of a character in the specified string and returns the portion of haystack, which starts at the last occurrence of the needle and goes until the end of haystack....

1 minute read.

PHP quotemeta() Function

PHP quotemeta() Function The quotemeta() function in PHP quotes the meta characters and returns a string with a backslash character (\) before some predefine characters. The predefined characters are as follows: period ...

1 minute read.

PHP is_real() Function

The PHP is_real () function in PHP is used to find whether the type of the specified variable is a float or not. It returns a Boolean value true if the parameter...

1 minute read.

WordPress Theme

Writing our WordPress Theme is relatively simple. Requirements: Before we begin, we need to know about the following set of requirements. We need to have full knowledge of WordPress setup, which is either...

2 minutes read.

PHP While Loop

PHP while loop is used to run the same block of code until a condition is met. It should be used if number of iteration it not known. Syntax: <?php while (condition){   //Code...

1 minute read.

PHP soundex() Function

PHP soundex() Function The soundex() function in PHP Calculates the soundex key(four character long alphanumeric string that represent English pronunciation of a word) of a string. Syntax soundex ( string $str ) Parameter str(required) – This parameter represents the input string. Return This function returns the soundex...

1 minute read.

PHP chunk_split() Function

PHP chunk_split() Function The chunk_split() function in PHP splits a string into a series of smaller parts. Syntax chunk_split(string,length,end) Parameter string(required)- It specifies the string to split. length(optional)- This parameter represents a number that defines the...

1 minute read.

PHP sizeof() Function

PHP sizeof() Function The sizeof() function in counts all elements and return the size of the array. This function is an alias of count(). Syntax sizeof( mixed $array_or_countable [, int $mode = COUNT_NORMAL ] )  Parameter array_or_countable(required)– This parameter represents the input array or countable object. mode(optional)-...

1 minute read.

PHP is_iterable() Function

The is_iterable() function in PHP verifies that the contents of the specified variable is an iterable value. Syntax is_iterable ( mixed $var ) var(required)- This parameter represents the value to check. Return This function returns a Boolean value TRUE if the parameter var is iterable, else it returns...

1 minute read.