PHP – echo and print statement



If there is an input then it must have an output. So in PHP also there is two statements which are used for displaying output data to the screen

  • echo
  • print

Both the statement are used for displaying data on the screen.

Difference between ‘echo’ and ‘print’

Examples of ‘echo’ statement

Example for single string input

<html>
<body>
<?PHP
	echo "
<h1>whatsnewtodayworld.com</h1>

";
	echo "welcome to PHP world 
";
?>
</body>
</html>

Example for multiple string input

<html>
<body>
<?PHP echo "PHP", "is", "one ", "of", "the","easiest","internet","technology."; ?>
</body>
 </html>

Input through variable

<html>
 <body>
<?PHP
	$a = "welcome to";
	$b = "whatsnewtodayworld.com";
	echo "
<h1>$a</h1>

";
	echo " $b
";
?>
</body>
</html>

Examples of ‘print’ statement

<html>
 <body>
 <?PHP
	print "
<h1>whatsnewtodayworld.com</h1>

";
	print "welcome to PHP world 
";
?>
</body>
 </html>
 

Input through variable

<html>
 <body>
<?PHP
	$a = "welcome to";
	$b = "whatsnewtodayworld.com";
	print "
<h1>$a</h1>

";
	print " $b
";
?>
</body>
 </html>