The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

What's the difference between PHP echo() and PHP print()?

Discussion in 'cPanel Developers' started by mario2027, Dec 1, 2010.

  1. mario2027

    mario2027 Registered

    Joined:
    Nov 30, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    What's the difference between PHP echo() and PHP print(),especially in the execution time?
     
  2. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi Mario2027,

    There are a few:
    echo:
    - will return nothing, it just sends the string to the output buffer
    - has short tag alias <?='something to print'?>, if you have short tags enabled
    - can take multiple, scalar argurments.
    print:
    - will return 1, always
    - only takes one argument

    Both are language constructs and are not functions.

    As far as execution time, I'm not sure that there is any difference. At compile time, there probably is, but other than the subtle differences I mention above, I don't think there's anything to be concerned about.

    I suggest looking at the PHP manual pages as the authoritative source for PHP calls:
    PHP: print - Manual
    PHP: echo - Manual
     
  3. jandrenievs

    jandrenievs Registered

    Joined:
    Dec 1, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    for PHP tutorials you can go to w3schools site..
     
  4. Sean.barron

    Sean.barron Active Member

    Joined:
    Aug 16, 2008
    Messages:
    33
    Likes Received:
    0
    Trophy Points:
    6
    PHP Print and Echo both output data to the screen in a same pattern but PHP Echo and PHP Print differ based on how they are structured.
     
  5. alferied

    alferied Registered

    Joined:
    Jan 13, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    In PHP, echo is not a function but a language construct. In PHP, print is not a realy function but a language construct. However, it behaves like a function in that it returns a value.
     

Share This Page