View Full Version : need to create new line break with \n
09-13-2011, 09:31 PM
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.
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
09-13-2011, 09:51 PM
\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 />.
09-13-2011, 10:24 PM
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.