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
Printable View
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
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.
If you use Phalanger, you can write entire projects in PHP and build them as .exe files. :D 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!
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;
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:Quote:
Originally Posted by php.net/echo
What's wrong with it Traq? UpdatePanels are the easiest way I've known so far to use AJAX and to have that ease with the scripting power of PHP...
One other small thing with Phalanger... if you add themod_monomodule to your Apache server, you can run a.aspx.phpsite on a Linux server. You don't even need IIS. :D
http://www.mono-project.com/Mod_mono
Mod_Mono is an Apache 2.0/2.2 module that provides ASP.NET support for the web's favorite server, Apache.
The module passes off requests for ASP.NET pages to an external program, mod-mono-server, which actually handles the requests. The communication between the Apache module and mod-mono-server is established using a Unix socket or a TCP socket.
Mod_mono is an Apache module that is hosted inside Apache. Depending on your configuration the Apache box could be one or a dozen of separate processes, all of these process will send their ASP.NET requests to the mod-mono-server process. The mod-mono-server process in turn can host multiple independent applications. It does this by using Application Domains to isolate the applications from each other, while using a single Mono virtual machine.
Although AppDomains provide an adequate level of isolation, mod_mono can also be configured to route different urls to different mod-mono-server processes. You can use this to:
- As an ISP, isolate different customers to different processes
- Allow experimental code to run in one server, independent of production code.
- Allow the kernel to enforce different isolation rules for different processes (for example with AppArmor or SELinux)
- Setup different CPU, Disk and memory quotas to different processes
This page shows you the current compatibility checklist for all .NET Frameworks:
http://www.mono-project.com/Compatibility