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
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 keyboard1333; 05-28-2012 at 02:03 AM.
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>| Deutsch | italiano | español | português | català | un peu de français | Ninasoma Kiswahili | 日本語の学生でした。| درست العربية
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.
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?
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.phppages, you can run PHP within ASP.NET pages.
A side effect of this is that now the PHP Libraries are within yourmachine.configfile, 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.
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>
Thanks for that info Apache Tech and Djr33!
Last edited by keyboard1333; 05-28-2012 at 03:30 AM.
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.
Adrian ~ facebook | gist/github
['66.215.156.37','208.75.149.97'] // ip,ip array!
"Take that sticker *off* your hat; you look stupid" --Wil Wheaton
ApacheTech (05-28-2012)
Interesting, I didn't even realise you could do that {echo(conenthere)}. I always just useecho "";
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:Originally Posted by php.net/echo
Last edited by traq; 05-28-2012 at 03:46 AM.
Adrian ~ facebook | gist/github
['66.215.156.37','208.75.149.97'] // ip,ip array!
"Take that sticker *off* your hat; you look stupid" --Wil Wheaton
Bookmarks