PHP  echo and print Statements

• In PHP there are two basic ways to get output: echo and print. 
• In this tutorial we use echo (and print) in almost every example. So, this chapter 
contains a little more info about those two output statements. 
• There are some differences between echo and print:
• echo - can output one or more strings 
• print - can only output one string, and returns always 1 
• Tip: echo is marginally faster compared to print as echo does not return any value 

The PHP echo Statement 

• echo is a language construct, and can be used with or without parentheses: echo or 
echo(). 
• Display Strings 
• The following example shows how to display different strings with the echo command 
(also notice that the strings can contain HTML markup): 

Example 

<?php 

echo "<h2>PHP is fun!</h2>"; 
echo "Hello world!<br>"; 
echo ("I'm about to learn PHP!<br>"); 
echo "This", " string", " was", " made", " with multiple parameters."; 

?> 

The PHP print Statement 

• print is also a language construct, and can be used with or without parentheses: print 
or print(). 
• Display Strings 
• The following example shows how to display different strings with the print command 
(also notice that the strings can contain HTML markup): 

Example 

<?php 

print "<h2>PHP is fun!</h2>"; 
print "Hello world!<br>"; 
print "I'm about to learn PHP!"; 

?> 

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post