Web Design Forum  
 
Go Back   Web Design Forum > Web Software > Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-18-2011, 06:38 PM   #1
Silver Member
 
Join Date: Aug 2011
Location: Tennessee
Posts: 112
Default Line break using php

What's the difference in using <br> and \n at the end of an echo statement.
Glenn is offline   Reply With Quote


Old 11-19-2011, 01:59 AM   #2
Silver Member
 
Join Date: Jul 2011
Posts: 146
Default

<br> is more correctly <br /> per latest HTML standards and causes a line break in the web page as presented by the browser, or when printed.

\n outputs is a new line character which is interpreted as white space and ignored by the browser, but is meaningful in text and source code files. Placing \n at the end of your echo strings will change your browser's display of source code from this:
HTML Code:
select name="select"><option value="A">A</option><option value="B">B</option><option value="C">C</option><option value="D">D</option></select>
to this:
HTML Code:
<select name="select">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
</select>
Note, I just discovered this fact: In order for \n to work, you must enclose your string to be echo'ed in double quotes, and escape double quotes that are part of the string.
__________________
space
Orchid Technical Services
Website Design/Development and Technical Support
DesignerBill is offline   Reply With Quote
Old 11-23-2011, 08:03 AM   #3
Bronze Member
 
Join Date: Feb 2010
Location: Satellite-Town, Lagos, Nigeria, West-Africa.
Posts: 89
Default

@DesignerBill, @Glenn
I have encountered the same problem with \n. So what i do is that i enclose the <br> tag in my echo statement.
goldenwaters is offline   Reply With Quote
Old 11-25-2011, 02:53 PM   #4
Silver Member
 
Join Date: Mar 2011
Posts: 231
Default

Hmm, that seems to be a likely solution. I'll try it out with mine.
computerGeek is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 09:47 AM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.