Page 1 of 1
printing newlines
Posted: Sat Sep 03, 2005 2:02 pm
by jaymoore_299
Code: Select all
for ($i = 0; $i <= 100; $i++) {
print $i . "\n";
}
why doesn't this print each in its own line on my browser? I get a continuous line of this 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
I even tried replacing the \n with \r\n and it still gives me one continuous line. How do I output each in its own line?
Posted: Sat Sep 03, 2005 2:04 pm
by ambivalent
Posted: Sat Sep 03, 2005 2:46 pm
by josh
view the source of the page, it's printing newlines but spec says browsers ignore whitespace & newlines
Posted: Sun Sep 04, 2005 6:50 am
by raghavan20
\n and \r do work well with files.
its been said that more than one space is ignored by browsers so you could see some relation between \n and spaces. ofcourse i think, \n is a collection of white spaces which are ignored by the browser. <br /> helps to get the format we require.
<br /> does not put a new line in the view source but its interpreted by the browser.
for ex:
if you type something like this in html
Code: Select all
<body>
<p>there is a huge gap betwen words</p>
</body>
you can see that there is only one space between a and huge and huge and gap. it automatically discards those spaces you have to use to get the number of spaces you require.