PHP - SPLessons
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. [php] <!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> [/php] Output: Below is an other example that displays variable including the text. [php] <!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> [/php] 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. [php] <!--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> [/php] Output:   Below example displays variable along with text. [php] <!DOCTYPE html> <html> <body> <?php $sp = 20; $sp1 = 60; echo "SP Lessons standards for : ".($sp+$sp1)."";?> </body> </html> [/php] 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.