|
-
Jan 9th, 2008, 06:38 AM
#1
Thread Starter
Fanatic Member
adding newline in php
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
-
Jan 9th, 2008, 07:16 AM
#2
Re: adding newline in php
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
Last edited by visualAd; Jan 9th, 2008 at 11:11 AM.
-
Jan 9th, 2008, 08:07 AM
#3
Re: adding newline in php
 Originally Posted by visualAd
// a new line in html
// test1<br />test2
Strictly speaking, that's XHTML (and even more strictly speaking, only in XML parsing mode, although no-one seriously observes that).
In HTML a new line is simply <br>.
-
Jan 9th, 2008, 11:11 AM
#4
Re: adding newline in php
I edited my post. I always observe that in XHTML.
-
Jan 9th, 2008, 11:24 AM
#5
Re: adding newline in php
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.
-
Jan 9th, 2008, 11:53 AM
#6
Re: adding newline in php
And IE6 doesn't recognise application/xhtml+xml MIME type.
-
Jan 9th, 2008, 11:55 AM
#7
Re: adding newline in php
Nor 7, which makes properly handling XHTML more or less a giant pain in the arse.
-
Jan 9th, 2008, 11:57 AM
#8
Re: adding newline in php
Doesnt the \n just do a simple new line?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 9th, 2008, 12:02 PM
#9
Re: adding newline in php
 Originally Posted by RobDog888
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.
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.
-
Jan 9th, 2008, 12:11 PM
#10
Re: adding newline in php
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 9th, 2008, 12:23 PM
#11
Re: adding newline in php
Definitely, unless you are caching the results and subsequently simply serving from the cache.
-
Jan 10th, 2008, 01:59 AM
#12
Frenzied Member
Re: adding newline in php
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 />!!!!!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|