Skip to content

PHP Tutorial PHP Syntax and Output

PHP echo

Lesson 13 of 369 2 min read By Deepak Paswan Updated Oct 5, 2026

echo is the tool you will use the most. It sends text to the output, which is the browser or the terminal.

index.php
PHP
<?php
echo "Hello, world!";
Output
OUTPUT
Hello, world!

echo can print strings, numbers and variables.

index.php
PHP
<?php
$name = "Maya";
$age = 28;

echo "Name: " . $name . "\n";
echo "Age: " . $age;
Output
OUTPUT
Name: Maya
Age: 28

The dot (.) joins strings together. The \n is a new line character. It makes a line break in the terminal. In a web page, a browser ignores a plain new line, so you use <br> or HTML tags instead, which the next example shows.

echo can print HTML. The browser reads it like any other HTML.

index.php
PHP
<?php
echo "<h2>Latest posts</h2>";
echo "<p>Nothing here yet.</p>";
Output
OUTPUT
<h2>Latest posts</h2><p>Nothing here yet.</p>

Several values in one echo

You can give echo several values separated by commas. No joining is needed.

index.php
PHP
<?php
$city = "Pune";
echo "I live in ", $city, ".";
Output
OUTPUT
I live in Pune.

echo is not a function

echo is a language construct, so you write it without parentheses. echo("Hi") also works, but the brackets do nothing. They just wrap one value.

The short echo tag

In templates, <?= $value ?> is a short form of <?php echo $value; ?>. You saw it in PHP Tags.

lightbulb
Use echo for output
Beginners often ask whether to use echo or print. The next lesson compares them. In day-to-day PHP, nearly everyone writes echo.

Exercise: a price tag

Store the number 499 in a variable called $price, then use one echo to print Price: 499 INR.

Show a possible solution
index.php
PHP
<?php
$price = 499;
echo "Price: " . $price . " INR";
Output
OUTPUT
Price: 499 INR