There are two options in PHP to get output: 1. echo and 2. print.



The PHP echo Statement

The echo command can output multiple parameters and echo has no return value.Therefore echo is a language construct not a function (like if,else statement), you can use it with or without parentheses e.g. echo or echo().

Display Text

Let’s see given below example will show you how to result a string of text with the echo command :

Example

<?php
echo "<h3>PHP is Easy to Use!</h3>";
echo "Hello Everyone!<br>";
echo "I'm excited to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with multiple parameters.";
?>

Output:

PHP is Easy to Use!

Hello Everyone!
I’m excited to learn PHP!
This string was made with multiple parameters.


Display Variables

The given following example will show you how to display variable using the echo command :

Example

<?php
$txt1 = "Learn More Technologies";
$txt2 = "Welcome To Netzole";
$x = 100;
$y = 10;

echo "<h3>" . $txt1 . "</h3>";
echo  $txt2 <br>";
echo $x + $y;
?>

Output:

Learn More Technologies

Welcome To Netzole”
110




The PHP print Statement

Print command work same as echo command. It means print statement also used to display output to the browser.The print statement also used with or without parentheses: print or print().


Conclusion:
Both echo and print statement works same way except that the print statement has a return value of 1.That’s why the echo is marginally faster than print.


Display Text

Let’s see given below example will show you how to result a string of text with the print command :

Example

<?php
echo "<h3>PHP is Easy to Use!</h3>";
print "Hello Everyone!<br>";
print "I'm excited to learn PHP!<br>";

?>

Output:

PHP is Easy to Use!

Hello Everyone!
I’m excited to learn PHP!


Display Variables

The given following example will show you how to display variable using the print command :

Example

<?php
$txt1 = "Learn More Technologies";
$txt2 = "Welcome To Netzole";
$x = 100;
$y = 10;

print "<h3>" . $txt1 . "</h3>";
print   $txt2 <br>";
print  $x + $y;
?>

Output:

Learn More Technologies

Welcome To Netzole”
110

Pin It on Pinterest

Shares
Share This