My first script! w00t!

Discussion in 'PHP' started by Carey, May 6, 2007.

  1. #1
    <?php
    $name = 'carey';
    echo $name;
    ?>

    LMAO.. I just learned how to do that...

    What is the difference between

    echo $name

    and

    print $name

    do they both work?
     
    Carey, May 6, 2007 IP
  2. Kalyse

    Kalyse Peon

    Messages:
    1,221
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Kalyse, May 6, 2007 IP
  3. Carey

    Carey Active Member

    Messages:
    370
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    80
    #3
    fixed ;)
    <?php
    $a = '1';
    $b = '5';
       if($a < $b)  {
          echo yes;
    }
       if($a > $b)  {
          echo No;
    }
    ?>
    Code (markup):
    fixed
     
    Carey, May 6, 2007 IP
  4. Not_My_Style

    Not_My_Style Peon

    Messages:
    535
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I believe only echo will work. Print is a PERL command.
     
    Not_My_Style, May 6, 2007 IP
  5. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Kalyse has correctly pointed out the PHP man pages for the commands "print" and "echo". They both accomplish the same thing, though there is a debate amoung users about which command is the better one to use for large projects.

    While PHP implements both commands, perl only implements print in the language.
     
    clancey, May 6, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Just for further reference, since you're learning. Integers don't need to go between quotes.
     
    nico_swd, May 7, 2007 IP
  7. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #7
    and you should wrap strings that you echo in single or double quotes, one word will work like echo word; but echo two words; would need to be echo 'two words';

    its best to wrap everything you echo in something

    I tend to use print, printf, sprintf when writing large applications, instead of using double quotes or echo ......
     
    krakjoe, May 7, 2007 IP
  8. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #8
    ^^ Good point, I didn't see that. Without quotes they will be considered constant. But since they're not defined as such it will leave an E_NOTICE.
     
    nico_swd, May 7, 2007 IP