PHP - SPLessons

PHP Echo

Chapter 5

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

PHP Echo

PHP Echo

shape Description

There are two basic ways to print the output in PHP.They are

Mostly echo is used to print the output. There is no much more difference in between these two elements.Both are similar but the difference is very small i.e. print will return a value of 1 and the echo won’t return any value.

Echo can take multiple arguments, but print can take only one argument at a time. Echo process the arguments very faster than print.

PHP Echo

shape Description

Echo command is used to output the text element. The text contains HTML elements also . Echo can be used to output the text element with or without parentheses.

shape Examples

Below example displays text elements including HTML element.

<!DOCTYPE html>
<html>
	<body>
		<?php
		   echo "Hello welcome to SP Lessons";
		   echo ("I am learning the scripts in SP Lessons");
		   echo("<h2>I learned so many things form SP Lessons</h2>");
		   echo  "Thanks to SP Lessons Team";
		?>
	</body>
</html>

Output:

Below is an other example that displays variable including the text.

<!DOCTYPE html>
<html>
	<body>
		<?php 
			$sp="Simple Programming"; 
			echo "Learn the Nice Scripts at SPLessons.com "; 
			echo "SP Lessons standards for : ".$sp." Lessons"; 
		?>
	</body>
</html>

Output:

shape Description

Similarly like echo statement, print statement can be used with or without parentheses.Print can take only one parameter.

shape Examples

The following is an example that displays text elements including HTML element.

<!--Please click on Run button below to see the output-->
<!DOCTYPE html>
<html>
	<body>
		<?php
		   print "Hello welcome to SP Lessons";
		   print ("I am learning the scripts in SP Lessons");
		   print("<h2>I learned so many things form SP Lessons</h2>");
		   print  "Thanks to SP Lessons Team";
		?>
	</body>
</html>

Output:

 

Below example displays variable along with text.


<!DOCTYPE html>
<html>
    <body>
        <?php $sp = 20; $sp1 = 60; 
        echo "SP Lessons standards for : ".($sp+$sp1)."";?>
    </body>
</html>

Output:

Summary

shape Key Points

  • The two ways to print the output in PHP is using “echo” and “print”.
  • Echo can be used to output the text element with or without parentheses.
  • Print can take only one parameter.