php problem

Sharky Forums


Results 1 to 5 of 5

Thread: php problem

  1. #1
    Goldfish Caesar War's Avatar
    Join Date
    Dec 2002
    Location
    Monterrey, Mexico
    Posts
    73

    Question php problem

    I decided to finally learn php and so I installed both apache and php on my laptop computer (laptop runs under XP) and run it as a server so i could go and do stuff.

    I was going through the ol hello world stuff and everything was going fine until i got to the special characters part

    if I go and do this

    <?php
    echo "Hi my name is \nCaesar";
    ?>

    it is supposed to output this:
    Hi my name is
    Caesar

    right ??

    but it's not doing it ! what is actually shows is:
    Hi my name is Caesar <-- without the newline

    however when i view the source on explorer it does shows like it is supposed to (with the newline thing)

    same thing happens with \r and \t

    doesnt happen with the other special chars... if I go and do this
    echo "Hi my name is \$Caesar";
    it does indeed shows
    Hi my name is $Caesar

    so... can somebody help me ?

  2. #2
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077
    PHP did it's job by printing the new line character, you're just no understanding the nature of HTML.

    HTML has a "<br>" tag for line breaks. New line characters in the source code mean absolutely nothing to the HTML parser. You have to remember that all whitespace characters are ignored by the HTML parser. (new lines are considered whitespace)

    However, if you want new line characters to actually display line breaks on your web page, simply wrap your content in the "<pre></pre>" tag.

  3. #3
    Goldfish Caesar War's Avatar
    Join Date
    Dec 2002
    Location
    Monterrey, Mexico
    Posts
    73
    I tought the PHP did the parsing part

    but I guess that makes more sense

    thank you
    Last edited by Caesar War; 01-04-2003 at 05:57 PM.

  4. #4
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077
    PHP parses PHP code on the server-side, and the web browser parses the resulting HTML on the client-side. Make sense?

  5. #5
    Goldfish Caesar War's Avatar
    Join Date
    Dec 2002
    Location
    Monterrey, Mexico
    Posts
    73
    yup... thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •