Newline "\n" does not work...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gregory

    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?
    [color=blue]
    >From example 2-17: Operating on Variables[/color]
    <?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;
    ?>

  • Chris Hope

    #2
    Re: Newline &quot;\n&quo t; does not work...

    Gregory wrote:
    [color=blue]
    > 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?
    >[color=green]
    >>From example 2-17: Operating on Variables[/color]
    > <?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;
    > ?>[/color]

    Refer to this thread from less than a month ago:



    TinyURL version of the above:



    --
    Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com

    Comment

    • Tom Thackrey

      #3
      Re: Newline &quot;\n&quo t; does not work...


      On 2-Apr-2005, "Gregory" <itisgregory@ya hoo.com> wrote:
      [color=blue]
      > 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?
      >[color=green]
      > >From example 2-17: Operating on Variables[/color]
      > <?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;
      > ?>[/color]

      Remember browsers expect HTML. HYML interprets newline as white space. To
      get a newline in HTML use

      print "<br>";



      --
      Tom Thackrey

      tom (at) creative (dash) light (dot) com
      do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)

      Comment

      • Gregory

        #4
        Re: Newline &quot;\n&quo t; does not work...

        Thanks for the valuable link! I am glad to see that I was not the only
        one who asked this question.

        Comment

        • Gregory

          #5
          Re: Newline &quot;\n&quo t; does not work...

          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=U TF-8&threadm=11
          2s8akhdek...

          Comment

          • JDS

            #6
            Re: Newline &quot;\n&quo t; does not work...

            On Sat, 02 Apr 2005 20:31:13 -0800, Gregory wrote:
            [color=blue]
            > Thanks for the valuable link! I am glad to see that I was not the only
            > one who asked this question.[/color]

            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 | jeffrey@example .invalid
            | http://www.newtnotes.com
            DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

            Comment

            Working...