473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

\n doesn't work

I am writing a program, and I am using \n in double-quoted print statements,
which should give me a line break. It doesn't work. I'm running Apache 2.0
and PHP 5, with Mozilla Firefox as a browser. What is wrong?
Jul 17 '05 #1
11 9770
Michael Bradley-Robbins wrote:
I am writing a program, and I am using \n in double-quoted print statements,
which should give me a line break. It doesn't work. I'm running Apache 2.0
and PHP 5, with Mozilla Firefox as a browser. What is wrong?


And... you're not confusing \n <--> <br /> ?

Hans

--
"He who asks a question is a fool for five minutes;
he who does not ask a question remains a fool forever"
Jul 17 '05 #2
Michael Bradley-Robbins wrote:
I am writing a program, and I am using \n in double-quoted print
statements, which should give me a line break. It doesn't work. I'm
running Apache 2.0 and PHP 5, with Mozilla Firefox as a browser. What
is wrong?


Look at the source (view-source in your browser) or wrap the output in
<pre></pre> tags.
JW

Jul 17 '05 #3
Michael Bradley-Robbins wrote:
I am writing a program, and I am using \n in double-quoted print
statements, which should give me a line break. It doesn't work. I'm
running Apache 2.0 and PHP 5, with Mozilla Firefox as a browser. What
is wrong?


This one needs to go in the FAQ list.

\n gives you a newline break in the data sent to the browser, so if you
select the view source option in your browser you'll see the source
does indeed have a linebreak where you are expecting it. However,
linebreaks are ignored in HTML. To create a line break in HTML which is
rendered in the browser, you need the <br> tag.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #4
Chris Hope wrote:
Michael Bradley-Robbins wrote:
I am writing a program, and I am using \n in double-quoted print
statements, which should give me a line break. It doesn't work. I'm
running Apache 2.0 and PHP 5, with Mozilla Firefox as a browser. What
is wrong?
This one needs to go in the FAQ list.


of an HTML group? I am sure it is. :-D.
\n gives you a newline break in the data sent to the browser, so if you
select the view source option in your browser you'll see the source
does indeed have a linebreak where you are expecting it. However,
linebreaks are ignored in HTML. To create a line break in HTML which is
rendered in the browser, you need the <br> tag.


Depends on what you want, it could be that you don't *want* the br element.

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
Jul 17 '05 #5
John Bokma wrote:
Chris Hope wrote:
Michael Bradley-Robbins wrote:
I am writing a program, and I am using \n in double-quoted print
statements, which should give me a line break. It doesn't work. I'm
running Apache 2.0 and PHP 5, with Mozilla Firefox as a browser.
What is wrong?


This one needs to go in the FAQ list.


of an HTML group? I am sure it is. :-D.


Heh - yes it's basic fundamental HTML skills we're talking about here.
Although I've seen this same question asked here a few times now...
\n gives you a newline break in the data sent to the browser, so if
you select the view source option in your browser you'll see the
source does indeed have a linebreak where you are expecting it.
However, linebreaks are ignored in HTML. To create a line break in
HTML which is rendered in the browser, you need the <br> tag.


Depends on what you want, it could be that you don't *want* the br
element.


Very true. I was making an assumption based on the same experience other
people have had when posting here about this problem. Plus it seems
very unlikely that print "\n" does not output a newline break ;)

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #6
Here's something that may help - especially if you have a bunch of
\n(s) in a database somewhere that you are generating dynamic pages
with (that you would like to see the line breaks in).

http://us2.php.net/nl2br

This little baby will insert a <BR> before any \n in whatever variable
or string you pass to it. I use this for pages where users get to type
info into a field and hit \n\n to create a new paragraph. When they
submit it to a database, it is raw, but when I pull it out, I pass it
through nl2br and it adds the <BR>(s) for me.

Not sure if that's what you are looking for, but it's worth saying just
in case.

Shane

Jul 17 '05 #7
Chris Hope wrote:
people have had when posting here about this problem. Plus it seems
very unlikely that print "\n" does not output a newline break ;)


Yup, true.

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
Jul 17 '05 #8
Chris Hope <bl*******@electrictoolbox.com> wrote:
This one needs to go in the FAQ list.


of an HTML group? I am sure it is. :-D.


Heh - yes it's basic fundamental HTML skills we're talking about here.
Although I've seen this same question asked here a few times now...


It already is (kind of):

msgid: 42***********************@news6.xs4all.nl
Subject: [FAQ] HTML is trunctating PHP text

Take a look at the source (the first place you should look to see what
PHP is actually doing) and you will see it's all there as

Jul 17 '05 #9
Chris Hope <bl*******@electrictoolbox.com> wrote:

Very true. I was making an assumption based on the same experience other
people have had when posting here about this problem. Plus it seems
very unlikely that print "\n" does not output a newline break ;)


It DOES output a newline break. Do a View->Source to prove it.

The issue is that newlines in HTML are just plain old white space, and are
removed when the page is rendered.

To get a line break rendered, you need to output a <br> tag.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 17 '05 #10
Tim Roberts wrote:
Chris Hope <bl*******@electrictoolbox.com> wrote:

Very true. I was making an assumption based on the same experience
other people have had when posting here about this problem. Plus it
seems very unlikely that print "\n" does not output a newline break ;)


It DOES output a newline break. Do a View->Source to prove it.

The issue is that newlines in HTML are just plain old white space, and
are removed when the page is rendered.

To get a line break rendered, you need to output a <br> tag.


I know that, and that's exactly what I posted in my reply to the OP ;)

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #11
Tim Roberts wrote:
To get a line break rendered, you need to output a <br> tag.


Depends :-D. In a <pre> it *does* count, and there are some other places
where it counts (sometimes in old browsers at unexpected places).

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
Jul 17 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: AnnMarie | last post by:
My JavaScript Form Validation doesn't work at all in Netscape, but it works fine in IE. I made some of the suggested changes which enabled it to work in IE. I couldn't make all the changes...
39
by: Mark Johnson | last post by:
It doesn't seem possible. But would the following also seem a violation of the general notions behind css? You have a DIV, say asociated with class, 'topdiv'. Inside of that you have an anchor...
3
by: Matt | last post by:
I want to know if readOnly attribute doesn't work for drop down list? If I try disabled attribute, it works fine for drop down list. When I try text box, it works fine for both disabled and...
149
by: Christopher Benson-Manica | last post by:
(Followups set to comp.std.c. Apologies if the crosspost is unwelcome.) strchr() is to strrchr() as strstr() is to strrstr(), but strrstr() isn't part of the standard. Why not? --...
6
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType =...
4
by: bbp | last post by:
Hello, In an ASPX page I have a "Quit" button which make a simple redirect in code-behind. This button doesn't work no more since (I think) I moved from the framework 1.0 to 1.1 and it doesn't...
3
by: Dave Moore | last post by:
Hi All, Ok, here's my problem. I want to open a file and process its contents. However, because it is possible that the file may not exist, I also want to check whether the file() function is...
10
by: Sourcerer | last post by:
I wrote this very simple code in .NET VC++. I compiled it on my system, and tried to run it on my friend's computer (he doesn't have the compiler). We both have Windows XP Professional. I have .NET...
6
by: Johnny Jörgensen | last post by:
I've got a usercontrol derived from a normal ComboBox that contains some special formatting code. On my main form I've got a lot of my custom comboboxes. I discovered a bug in the derived...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.