New to PHP question
| From: | Don Collier | Date: | Wed, 28 Jan 2009 19:05:34 +0000 |
| Subject: | New to PHP question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-287284@lists.php.net to get a copy of this message | ||
I am just learning PHP from the O'Reilly "Learning PHP 5" book and I have a question regarding the formatting of text. Actually it is a couple of questions.
First, when I use the \n and run the script from the command line it works great. When I run the same code in a browser it does not put the newline in and the text runs together. I know that I can use <br/> to do the same thing, but why is it this way?
The second question is closely related to the first. When formatting text using printf the padding works great when running from the command line but not at all when in a browser.
Here is the code that I am working with:
<?php
$hamburger = 4.95;
$chocmilk = 1.95;
$cola = .85;
$subtotal = (2 * $hamburger) + $chocmilk + $cola;
$tax = $subtotal * .075;
$tip = $subtotal * .16;
$total = $subtotal + $tip + $tax;
print "Welcome to Chez Don.\n";
print "Here is your receipt:\n";
print "\n";
printf("%1d %9s \$%.2f\n", 2, 'Hamburger', ($hamburger * 2));
printf("%1d %9s \$%.2f\n", 1, 'Milkshake', 1.95);
printf("%1d %9s \$%.2f\n", 1, 'Soda', .85);
printf("%25s: \$%.2f\n",'Subtotal', $subtotal);
printf("%25s: \$%.2f\n", 'Tax', $tax);
printf("%25s: \$%.2f\n", 'Tip', $tip);
printf("%25s: \$%.2f\n", 'Total', $total);
?>
Thanks for the help everyone.