Alice Wei wrote:

Date: Mon, 9 Mar 2009 13:28:19 +0100
Subject: Re: [PHP] Line Break Problem

Stuart schreef:
2009/3/9 Alice Wei <>

 I have a question regarding using line breaks in PHP. I have the code
something like:

      echo "1" . "\t " . $x . "\t" . $y . "\r\n";

When I run the code, it looks like a whole blob of text, but when I use
"View Source", the line breaks are formatted then correctly.
Anyone can please tell me if this is what this is supposed to be?
If so, how can I get the user to see the line break as they are, do I have
to use <br>?
you can also wrap the output in question in a <pre> tag:

1       X       Y
2       X       Y

alternatively use the nl2br() function ... but that won't help
with displaying the tabs.

note that there is a difference between the output of your script
(which you can view using 'View Source' when the output is sent to
the browser) and the representation of that same source
(by which I mean how the the source is rendered [in the browser, in this

HTML rendering ignores tabs, carriage returns and multiple consecutive spaces
found in the source (with the exception of the <pre> tag, possibly the <code> 
additionally the CSS attribute 'whitespace', IIRC, can be used to force 
all whitespace chars.

Hi, all:

Thanks to all who replied. It looks like that a simple <pre> tag works great. Looks like I didn't realize that \r\n does not reflect itself to the screen.


All-in-one security and maintenance for your PC.  Get a free 90-day trial!

just a little side-note "\r\n" is windows specific, "\n" is linux but also works in many windows applications - the best option though is to use the php constant PHP_EOL as such which will use the correct end of line terminator for whichever platform your app is on, thus making your scripts portable and saving you future headaches :)

echo "1" . "\t " . $x . "\t" . $y . PHP_EOL;

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to