By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,961 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,961 IT Pros & Developers. It's quick & easy.

Newline "\n" does not work...

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.