hi,
in php how to add a newline?
for example:
echo "Test1";
echo "Test2;
Result should be look like this:
Test1
Test2
but isnt working :confused:
Printable View
hi,
in php how to add a newline?
for example:
echo "Test1";
echo "Test2;
Result should be look like this:
Test1
Test2
but isnt working :confused:
Echo just outputs what you put between the quotes. If you try:
PHP Code:// two lines
echo "Test
test1";
// a new line in linux
echo "test1\ntest2";
// a new line in windows
echo "test1\r\ntest2";
// a new line in MAC
echo "text1\rtest2";
// a new line in XHTML
// test1<br />test2
Strictly speaking, that's XHTML (and even more strictly speaking, only in XML parsing mode, although no-one seriously observes that).Quote:
Originally Posted by visualAd
In HTML a new line is simply <br>.
I edited my post. I always observe that in XHTML. ;)
Slightly bad wording by me. I meant that no-one really observes the difference between XHTML in XML parsing mode and in text/html mode; most people send XHTML in text/html mode anyway. So rather than <br> in XML mode you will almost always see <br /> in text/html mode; which is fine since no real-world user agents care anyway.
And IE6 doesn't recognise application/xhtml+xml MIME type.
Nor 7, which makes properly handling XHTML more or less a giant pain in the arse.
Doesnt the \n just do a simple new line?
It represents a newline character, yes, but whether a newline is actually a line break depends on the platform. On Unix/Linux it is all that is required. On Windows, most applications recognise it as a line break, but some require \r\n. And on older Mac platforms only \r is required although \r\n will function as well. Newer Mac platforms, I believe, use only \n, since they're now based on Unix.Quote:
Originally Posted by RobDog888
This all applies to text-only response bodies of course. If you are using HTML or XML then formatting your response body nicely is generally over the top.
Thanks for the details.
So then when I format my dynamic code to be correctly indented when a user "view source" is over the top :lol:
Definitely, unless you are caching the results and subsequently simply serving from the cache. ;)
You dont say why you are asking, so just saying for incase this help:
I store breaks as new line chars, then if i want to display it on a page, i use the build in nl2br function
by the way....there's no <br> in xhtml...it's <br />!!!!!!!