Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
09-13-2011, 10:31 PM #1
- Join Date
- May 2008
- Thanked 5 Times in 5 Posts
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.
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, 10:51 PM #2
- Join Date
- Jul 2011
- Thanked 171 Times in 171 Posts
\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, 11:24 PM #3
- Join Date
- Feb 2011
- Your Monitor
- Thanked 537 Times in 524 Posts
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.
See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/
Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!