473,223 Members | 1,662 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,223 software developers and data experts.

Newline "\n" does not work...

I am working through the exercises in the book "Learning PHP 5". I am
using OS 10.3.7, with Apache, Safari and IE. When I execute the
following code, the newline "\n" does not work. The ouput is all on
one line in both browsers. I read through the PHP website to no avail.
What is wrong?
From example 2-17: Operating on Variables

<?php
$price = 23.95;
$tax_rate = 0.08;
$tax_amount = $price * $tax_rate;
$total_cost = $price + $tax_amount;
$username = 'james';
$domain = '@example.com';
$email_address = $username . $domain;

print 'The tax is ' .$tax_amount;
print "\n";
print 'The total cost is ' .$total_cost;
print "\n";
print $email_address;
?>

Jul 17 '05 #1
5 3720
Gregory wrote:
I am working through the exercises in the book "Learning PHP 5". I am
using OS 10.3.7, with Apache, Safari and IE. When I execute the
following code, the newline "\n" does not work. The ouput is all on
one line in both browsers. I read through the PHP website to no
avail.
What is wrong?
From example 2-17: Operating on Variables

<?php
$price = 23.95;
$tax_rate = 0.08;
$tax_amount = $price * $tax_rate;
$total_cost = $price + $tax_amount;
$username = 'james';
$domain = '@example.com';
$email_address = $username . $domain;

print 'The tax is ' .$tax_amount;
print "\n";
print 'The total cost is ' .$total_cost;
print "\n";
print $email_address;
?>


Refer to this thread from less than a month ago:

http://www.google.co.nz/groups?hl=en...3D20%26hl%3Den

TinyURL version of the above:

http://tinyurl.com/5w9gh

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Jul 17 '05 #2

On 2-Apr-2005, "Gregory" <it*********@yahoo.com> wrote:
I am working through the exercises in the book "Learning PHP 5". I am
using OS 10.3.7, with Apache, Safari and IE. When I execute the
following code, the newline "\n" does not work. The ouput is all on
one line in both browsers. I read through the PHP website to no avail.
What is wrong?
From example 2-17: Operating on Variables

<?php
$price = 23.95;
$tax_rate = 0.08;
$tax_amount = $price * $tax_rate;
$total_cost = $price + $tax_amount;
$username = 'james';
$domain = '@example.com';
$email_address = $username . $domain;

print 'The tax is ' .$tax_amount;
print "\n";
print 'The total cost is ' .$total_cost;
print "\n";
print $email_address;
?>


Remember browsers expect HTML. HYML interprets newline as white space. To
get a newline in HTML use

print "<br>";

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #3
Thanks for the valuable link! I am glad to see that I was not the only
one who asked this question.

Jul 17 '05 #4
I will do that...now I understand what is going on...Chris Hope posted
this link that helped...
http://www.google.co.nz/groups ?hl=en&lr=&ie=UTF-8&threadm=11
2s8akhdek...

Jul 17 '05 #5
JDS
On Sat, 02 Apr 2005 20:31:13 -0800, Gregory wrote:
Thanks for the valuable link! I am glad to see that I was not the only
one who asked this question.


And you seldom will be. Google a bit before asking. (And no, I'm not
being rude, mean, or an asshole by saying this, or in this tone).

--
JDS | je*****@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Jul 17 '05 #6

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

Similar topics

6
by: Marty | last post by:
Hi, I would like to replace "\r\n" by "_" within a specific string. I tried : strMyString.Replace('\r', '_'); strMyString.Replace('\n', '_'); or...
1
by: Asha | last post by:
greetings... i want to split a new line from an input text area and here's what i did string.Split("\n \r ", ","); the result, nothing happen... then i tried this ...
0
by: Howard Kaikow | last post by:
I have never seen WriteLine fail to produce a NewLine, at least, not until now: I was playing with an example given on pages 51-52 of the book "A Visual Basic 6 Programmer's Toolkit". The book...
0
by: Howard Kaikow | last post by:
I have never seen WriteLine fail to produce a NewLine, at least, not until now: I was playing with an example given on pages 51-52 of the book "A Visual Basic 6 Programmer's Toolkit". The book...
7
by: Alex Nordhus | last post by:
I am looking for a way to strip the blank line and the empty newline at the end of the text file. I can get the blank lines removed from the file but it always leaves the end line (which is blank)...
2
by: Karlo Lozovina | last post by:
Consider this short script: --- from time import time, sleep st = time() print 'Start: %f, ' % st, sleep(10) sp = time() print 'Stop: %f, Duration: %f' % (sp, (st - sp))
14
by: stevek | last post by:
Following code does not produce any new lines. Any ideas. echo "This spans\multiple lines. The newlines will be\noutput as well.";
2
by: Juha Nieminen | last post by:
I assume that using '\n' to print a newline is not portable because in some systems newline consists actually of two characters and '\n' is only one. Thus the only portable way of printing a...
2
by: manontheedge | last post by:
I'm getting weird results in my program, and even compile time errors, and I've got it down to the "\n" command I use in "printf()". The program this is happening in deals with multiple processes,...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...

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.