PHP echo

PHP echo and print

PHP echo and print statements are the two  functions used  to output something on the screen.PHP variables can be displayed or output to the screen using these two statements.

PHP echo and print

These PHP echo and  print  are almost the same.They both display or output data on the screen.

Differences between the two statements

1.print function has a return value of 1 while echo has no return value

2.print function only takes one argument while echo takes multiple parameters

3.Print function is slower compared to echo function

PHP echo– can be used without parentheses or with them.There will be no error.

Example

PHP echo

Note:The text displayed can also contain html tags


<?php
echo "<h1>I love Programming in PHP</h1>";
echo "PHP is the best<br>";

echo "What  ", "your ", "name ", "? ";//echo made multiple paranthesis
?>

How to output Variables with echo statement.

Below code will shows how to display text and variables using echo.


<?php
$text1 = "PHP is simple to learn ";
$text2 = "Programming IN PHP";
$num1 = 10;
$num2 = 17;

echo "<h1>$text1</h1>";
echo "Study  $text2<br>";
echo $num1 + $num2;
?>

PHP print-similar to echo,with or without paranthesis,the statement will work fine i.e print or print()

 

Outputing text with print

Text can contain html tag.

<?php
print "<h1>I love Programming in PHP</h1>";
print "PHP is the best<br>";

print "What  ", "your ", "name ", "? ";//echo made multiple paranthesis
?>

<strong> 

How to output Variables with print.

Below code will shows how to display text and variables using print.


&lt;?php
$text1 = "PHP is simple to learn ";
$text2 = "Programming IN PHP";
$num1 = 10;
$num2 = 17;

echo "&lt;h1&gt;$text1&lt;/h1&gt;";
echo "Study  $text2&lt;br&gt;";
echo $num1 + $num2;
?&gt;

See my Next  Post  on                                                                                                      See my Previous Post

Data Types in PHP 5             PHP Variable Scope

 

About the Author: Eric K

My name is Eric.Am a software developer with skills in Php,Mysql, Java , Android,Node.js Above all, I have certification in Cisco Networking Associate (CCNA) and holds degree in Information Technology. Hire me: Email : kawi3462@gmail.com