Trouble with /n
Moderator: General Moderators
Trouble with /n
I see this subject has been hashed over but I cannot seem to
make the \n linefeed work in my version of PHP (4.3.1) running
on Apache 1.3.27 in Slackware Linux 9.0.
As an example:
<?
$fruits = array( 'strawberry' => 'red' , 'banana' => 'yellow' );
echo "A banana is $fruits[banana].\n";
echo "\n";
echo "A banana is $fruits[banana].\n";
?>
The above never produces a line feed. I have also tried "\n\n"; &
"\r\n"; with the same result. The only thing that will work is to replace
the \n with the html <br> tag. I am viewing the php output in IE 5.5.
I thought this might be the result of improper settings in php.ini but
a perusal of that file revealed nothing that would lead me to believe
there was anything to alter there.
While this is not a big problem, I am totally befuddled by the
inoperability of this piece of code and wish to track down the
problem.
Anyone have an idea? TIA
make the \n linefeed work in my version of PHP (4.3.1) running
on Apache 1.3.27 in Slackware Linux 9.0.
As an example:
<?
$fruits = array( 'strawberry' => 'red' , 'banana' => 'yellow' );
echo "A banana is $fruits[banana].\n";
echo "\n";
echo "A banana is $fruits[banana].\n";
?>
The above never produces a line feed. I have also tried "\n\n"; &
"\r\n"; with the same result. The only thing that will work is to replace
the \n with the html <br> tag. I am viewing the php output in IE 5.5.
I thought this might be the result of improper settings in php.ini but
a perusal of that file revealed nothing that would lead me to believe
there was anything to alter there.
While this is not a big problem, I am totally befuddled by the
inoperability of this piece of code and wish to track down the
problem.
Anyone have an idea? TIA
The <br> is an old standard. The W3C (World Wide Web Consortium) decided that every tag should have a closing tag, or be the closing tag at the same time. Just as <p></p> the new line <br> became <br />.
http://www.w3schools.com/tags/tag_br.asp
http://www.w3schools.com/tags/tag_br.asp
<br /> (there's nothing wrong wiht <br/>) it's a more XHTML style of typical HTML <br>. The slash means that this is one tag element, and every HTML element must be closed. So if you have paragraph <p> it's a block element so you close it in typical way </p>.
UPDATE: After posting I saw that we had the same ideas like Icidiw

UPDATE: After posting I saw that we had the same ideas like Icidiw
still useful
<br /> is the right way for new lines in HTML but using the \n in your code is also very helpful especially generating html as it will format it nicely if you ever have to do a view source to see what the html looks like you are generating.
ie
will give you nicely formated hmtl.
phpScott
ie
Code: Select all
<?php
print"something";
print "<br />\n";
print"something else";
?>phpScott
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
[OT]
... But slowly but surely I am winning the standards over backwards compatibility hacks argument
. XHTML strict here I come...
Mac
I don't have any choice, personally I would settle for 'degrades gracefully' but the powers that be wish the site to look pretty much the same in Netscape 4 as it does in the latest browsersreleasedj wrote:I wouldn't bother trying to make Netscape 4 happy.
Mac