PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

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

Comment on this Question and Answer >>>

ASK A QUESTION

More strings PHP Questions

How do I break email address into username and hostname?

print(1 . " + " . 2 . " = " . 1+2 . "n"); gives answer 3 why?

How do I make the first letter of a string uppercase?

How do I one-way encrypt a string in PHP?

What is the difference between join and implode in PHP?



Custom Search