Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-13-2011, 09:31 PM   PM User | #1
surreal5335
Regular Coder

 
Join Date: May 2008
Posts: 446
Thanks: 23
Thanked 5 Times in 5 Posts
surreal5335 is an unknown quantity at this point
need to create new line break with \n

I am working on some hw and I need to create a new line using \n. I have putting it in all different ways with an echo, but the best I get is make \n not be visible.

echo $var."\n";

I will put this in a foreach loop, but all the output stays on the same line. I have read it will only work when put inside html elements, so I had the list get created inside <p></p> tags... no difference.

I now understand why I always use <br /> for new lines... '\n' is very fickle.

I appreciate the help
surreal5335 is offline   Reply With Quote
Old 09-13-2011, 09:51 PM   PM User | #2
BluePanther
Senior Coder

 
Join Date: Jul 2011
Posts: 1,226
Thanks: 3
Thanked 171 Times in 171 Posts
BluePanther is on a distinguished road
\n itself isn't fickle, but it is pretty specific in it's uses. If you're actually wanting new lines in you viewable text (what the user sees when looking at your script/text) then your "\n" will work. In terms of html, it wont always work. In my experience, if you're wanting new lines between tags in your html source, putting a "\n" inbetween tags will do that. If you're wanting breaks in your html text, either use <p> tags or <br />.

I don't really know the specifics, but I know that your browser wont treat the \n as expected in some scenarios, so it's best to stick by my rule imo - break in source, \n; break in text, paragraphing or <br />.
BluePanther is offline   Reply With Quote
Old 09-13-2011, 10:24 PM   PM User | #3
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
As BP says, \n (inside double quotes) works for text based content (EG text files) but it doesn't work in html.

html is exactly what its name suggests - markup language. Markup means tags to describe things. That means that any breaks are marked up using the <br> tag. That is how html works and that is why your code does not work.

Normal text is not a markup language.

Html is a web page. The html source is supposed to be a set of mark up INSTRUCTIONS on how to display the content. Therefore line / carriage returns are ignored.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 08:25 PM.


Advertisement
Log in to turn off these ads.