473,406 Members | 2,549 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,406 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 3727
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.