Q:

How to create a new line in PHP

0

How to create a new line in PHP

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the Newline Characters '\n' or '\r\n'

You can use the PHP newline characters \n or \r\n to create a new line inside the source code. However, if you want the line breaks to be visible in the browser too, you can use the PHP nl2br() function which inserts HTML line breaks before all newlines in a string.

Let's take a look at the following example to understand how it basically works:

<?php
echo "If you view the page source \r\n you will find a newline in this string.";
echo "<br>";
echo nl2br("You will find the \n newlines in this string \r\n on the browser window.");
?>
 

Note: The character \n writes a newline in UNIX while for Windows there is the two character sequence: \r\n. To be on safe side use the \r\n instead.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP  and MySQL Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to find string length in PHP... >>
<< How to remove white space from the end of a string...