newline in ubuntu+firefox

Discussion in 'PHP' started by El alma, Apr 1, 2008.

  1. #1
    Hi,
    I have some troubles with a simple Php example. The following code returns a right output running via Common Line Interface (CLI), but the newlines (\n) are ignored when I try to view it with firefox. What could the reason be?
    There's no problem when I put the php code between <pre></pre>, but how avoid this?
    Thanks in advance.
    Fran

    <?php
    $price = 3.95;
    $tax_rate = 0.08;
    $tax_amount = $price * $tax_rate;
    $total_cost = $price + $tax_amount;

    print 'The tax is '.$tax_amount;
    print "\n"; // this prints a linebreak
    print 'The total cost is '.$total_cost;
    print "\n"; // this prints a linebreak
    ?>
     
    El alma, Apr 1, 2008 IP
  2. singh.ajit05

    singh.ajit05 Peon

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi alma,

    You can use this one.. It will work on all browser

    <?php
    $price = 3.95;
    $tax_rate = 0.08;
    $tax_amount = $price * $tax_rate;
    $total_cost = $price + $tax_amount;

    print 'The tax is '.$tax_amount;
    print "<br>"; // this prints a linebreak
    print 'The total cost is '.$total_cost;
    print "<br>"; // this prints a linebreak
    ?>
     
    singh.ajit05, Apr 1, 2008 IP