Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

PHP echo / print

PHP echo and print Statements

echo and print are quite similar, as both are used to output data to the screen.

The differences are minor: echo has no return value, while print returns 1, allowing it to be used in expressions. echo can accept multiple parameters (though this is uncommon), whereas print can take only one argument. Additionally, echo is slightly faster than print.

The PHP echo Statement

The echo statement can be used with or without parentheses: echo or echo().

Example

echo "Hello";
//same as:
echo("Hello");

Display Text

The following example demonstrates how to output text using the echo command (note that the text can include HTML markup):

Example

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.";

Display Variables

The following example illustrates how to output text and variables using the echo statement:

Example

$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";

echo
"<h2>$txt1</h2>";
echo "<p>Study PHP at $txt2</p>";