In this tutorial, you shall learn how to output a string in PHP using echo() function, with syntax and example programs.

PHP echo

In PHP, echo takes one or more expressions that evaluate to string, and outputs them. If any of the expression is not a string, then it is implicitly converted to string.

Syntax

The syntax of echo is

</>
Copy
//echo single value
echo($expression);
//echo multiple values
echo($expression_1, $expression_2, $expression_3);
//echo without parenthesis
echo $expression;
echo $expression_1, $expression_2, $expression_3;

where

ParameterDescription
$expressionAn expression to be output. Typically a string value. If not a string, then it is converted to a string to print to output.

echo does not return a value.

Usually, echo without parenthesis is used.

Examples

1. Echo a string “Hello World” to output

In the following example, we print a string "Hello World" to output using echo.

PHP Program

</>
Copy
<?php
echo 'Hello World';
?>

Output