Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: echo vs print

  1. #1
    Join Date
    Mar 2011
    Location
    N 11░ 19' 0.0012 E 142░ 15' 0
    Posts
    1,524
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default echo vs print

    Hello everyone,
    Just wondering, what is the difference between echo and print. I always use echo (because it's faster according to the php tips thread) but are there any other things different between them?

    Thanks, Keyboard1333
    Last edited by keyboard; 05-28-2012 at 02:03 AM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    They're effectively the same thing and echo is most commonly used in PHP, from what I've seen.

    In specific technical ways (that are usually irrelevant) they do differ slightly, so that if you're not using them to output HTML the difference might matter. So print works better from the command line, I believe. But since PHP is almost always used for HTML, it probably won't matter too much for you.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    If you use Phalanger, you can write entire projects in PHP and build them as .exe files. If it does have differences in the way it compiled, it may cause problems with that.

  4. #4
    Join Date
    Mar 2011
    Location
    N 11░ 19' 0.0012 E 142░ 15' 0
    Posts
    1,524
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    Hmmm, on a second note, what is Phalanger?
    I googled it and it says you can compile php into exe... What use is this? You wouldnt't be able to run it on a server.. would you?

  5. #5
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    Phalanger is an open source add-on for Visual Studio 2010. If you can get to work properly (which I haven't been able to yet, not fully anyway) you can seamlessly use PHP alongside ASP.NET within VS2010. It's immensely powerful if you think about the ramifications of that. You can use the .NET Library within PHP scripts and using .aspx.php pages, you can run PHP within ASP.NET pages.

    A side effect of this is that now the PHP Libraries are within your machine.config file, you can use PHP within Windows Applications as well. Because the .exe files are compiled to be portable, any libraries needed to run the program will be compiled either as .dll files or bundled into the executable.

    Theoretically, you could even write full .dll libraries in PHP that could be rolled out across a site. So long as Phalanger is used to write a fully PHP site, it will be able to use any .dll file it has access to, regardless of the language it's coded in.

  6. #6
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    Imagine this:

    HTML Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    
    <?php
    
        $date = date([b]F j, o[/b]);
        $time = date([b]g:i a[/b]);
    
        $page_title = "Phalanger Example";
    
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head runat="server">
            <!-- Start Meta Block -->
            <meta content="text/html; charset=iso-8859-1" http-equiv="content-type" />
            <meta content="Phalanger Example" name="description" />
            <meta content="php, asp.net, phalanger" name="keywords" />
            <meta content="all,index,follow" name="robots" />
            <meta content="noodp" name="msnbot" />
            <meta content="global" name="distribution" />
            <!-- End Meta Block-->
            <title><?php echo $page_title ?></title>
        </head>
    
        <body>
            <form id="pageForm" runat="server">
    
                <asp:ScriptManager ID="AJAXConrol" runat="server">
                </asp:ScriptManager>
    
                <asp:UpdatePanel ID="udpAJAXPanel" runat="server">
                    <ContentTemplate>
                        <?php
                            echo "Welcome! The date is $date and the time is currently $time.";
                        ?>
                    </ContentTemplate>
    
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="btnUpdateAJAXPanel" EventName="click" />
                    </Triggers>
                </asp:UpdatePanel>
    
                <asp:Button ID="btnUpdateAJAXPanel" runat="server" Text="Update Time" />
            </form>
        </body>
    </html>

  7. #7
    Join Date
    Mar 2011
    Location
    N 11░ 19' 0.0012 E 142░ 15' 0
    Posts
    1,524
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    Thanks for that info Apache Tech and Djr33!
    Last edited by keyboard; 05-28-2012 at 03:30 AM.

  8. #8
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by ApacheTech View Post
    Imagine this:
    ...
    hehehe ... I'd rather not

    going back to print vs. echo, there is one other difference: print takes only one argument; echo can take multiple arguments. This seems like it could be useful in some situations, sometime, but I've never actually discovered what situation that might be.
    PHP Code:
    <?php
    $a 
    "I ";
    $b "don't ";
    $c "need ";
    $d "to ";
    $e "concatenate!";

    echo 
    $a,$b,$c,$d,$e;
    Last edited by traq; 05-28-2012 at 03:43 AM.

  9. The Following User Says Thank You to traq For This Useful Post:

    ApacheTech (05-28-2012)

  10. #9
    Join Date
    Mar 2011
    Location
    N 11░ 19' 0.0012 E 142░ 15' 0
    Posts
    1,524
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    Interesting, I didn't even realise you could do that { echo(conenthere) }. I always just use echo "";

    Also - http://www.dynamicdrive.com/forums/s...ad.php?t=51208 - #2 says echo is faster???

  11. #10
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by keyboard1333 View Post
    Interesting, I didn't even realise you could do that { echo(conenthere) }. I always just use echo "";

    Also - http://www.dynamicdrive.com/forums/s...ad.php?t=51208 - #2 says echo is faster???
    yes, I stand corrected. (I edited my above post.) but read - the difference is insignificant in practice.

    also, the parenthesis were a mistake as well - they're allowed, but cause problems sometimes. it's better not to use them.

    also also, this is interesting:
    Quote Originally Posted by php.net/echo
    PHP Code:
    <?php
    // Because echo does not behave like a function, the following code is invalid.
    ($some_var) ? echo 'true' : echo 'false';

    // However, the following examples will work:
    ($some_var) ? print 'true' : print 'false'// print is also a construct, but
                                                // it behaves like a function, so
                                                // it may be used in this context.
    echo $some_var 'true''false'// changing the statement around
    Last edited by traq; 05-28-2012 at 03:46 AM.

Bookmarks

Posting Permissions

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