Table of Contents
The echo statement can be used with or without parentheses: echo or echo().
<h4>echo_Statement</h4>
<p>The echo statement can be used with or without parentheses: echo or echo().</p>
<?php
echo "Hello";
//same as:
echo ("Hello");
?>
Result View Example
In the example below, we use the PHP echo statement to output the text "Hello World!".
<h2>phpTeeratus</h2>
<p>From w3schools.com, Experiment by Teeratus_R </p>
<?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with multiple parameters.";
?>
Result View Example
In the example below, we use the PHP echo statement to output the text "Hello World!", but we use a variable to output the text:
<h4>Display_Variables</h4>
<p>Display Variables</p>
<hr>
<?php
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
echo "<h2>$txt1</h2>";
echo "<p>Study PHP at $txt2</p>";
?>
Result View Example
<h4>Using_Single_Quotes</h4>
<p>From w3schools.com, Experiment by Teeratus_R </p>
<?php
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
echo '<h2>' . $txt1 . '</h2>';
echo '<p>Study PHP at ' . $txt2 . '</p>';
?>
Result View Example
<h4>phpTeeratus</h4>
<p>From w3schools.com, Experiment by Teeratus_R </p>
<?php
// The PHP print Statement
print "Hello";
//same as:
print("Hello");
?>
Result View Example
The following example shows how to output text with the print command
<h4>print_Display_Text</h4>
<p>From w3schools.com, Experiment by Teeratus_R </p>
<?php
print "<h2>PHP is Fun!</h2>";
print "Hello world!<br>";
print "I'm about to learn PHP!";
?>
Result View Example
<h4>Print Display Variables</h4>
<p>The following example shows how to output text and variables with the print statement:</p>
<?php
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
$x = 5;
$y = 4;
echo "<h2>" . $txt1 . "</h2>";
echo "Study PHP at " . $txt2 . "<br>";
echo $x + $y;
?>
Result View Example
Strings are surrounded by quotes, but there is a difference between single and double quotes in PHP.
When using double quotes, variables can be inserted to the string as in the example above.
When using single quotes, variables have to be inserted using the . operator, like this:
<h4>print_Using_Single_Quotes</h4>
<?php
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
print '<h2>' . $txt1 . '</h2>';
print '<p>Study PHP at ' . $txt2 . '</p>';
?>
Result View Example
Document in project
You can Download PDF file.