Frank Stanovcak wrote:
> "Don Collier" <dcoll...@collierclan.com> wrote in message 
> news:4980ac7e.2080...@collierclan.com...
>> 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.
> 
> It has specifically to do with how the browser renders the page.  part of 
> the spec for rendering is that newlines are ignored, and the only way to get 
> a line to break in a browser window is with the use of <br>.  As for the 
> padding this is the same issue.  In Browswer rendering all white space 
> except the first one is ignored, and you have to use &nbsp; for aditionall 
> spaces.
> 

You could always wrap things in a <pre>...</pre>

or tell CSS to handle white-space: pre;  where needed.

http://www.w3schools.com/CSS/pr_text_white-space.asp

> ie: 3 space would be ' &nbsp; ' or '&nbsp; &nbsp;'
> 
> Hope that helps!
> 
> Frank. 
> 
> 
> 


-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to