PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

How do I display newline characters on a webpage?


Newline characters, or '\n' are ignored on the web browser which is looking for HTML, which may confuse you if you are used to using the command lines where newline characters do what you expect them to do.

One way to get them to display is to convert them to the HTML line break character
through use of the nl2br function.

So for instance if you have

$mytext = "this is my \n text \n with new line characters";

echo nl2br($mytext);

Then the resultant information sent to the web browser looks like this:

this is my

text

with new line characters

More strings PHP Questions

How do I count how many times each character occurs in a string?
How do I check if a string contains HTML?
How do I escape a string with slashes?
How do I convert newlines to HTML line break tags?
How can I repeat a string variable several times?