1 of 410 menu

The echo Function

The echo function outputs the passed strings. Unlike the print function, echo can take multiple parameters and does not return a value. It is one of the most frequently used constructs in PHP for outputting data.

Syntax

echo string1, string2, ..., stringN;

Example

Simple string output:

<?php echo 'Hello World'; ?>

Code execution result:

Hello World

Example

Outputting multiple strings:

<?php echo 'Hello', ' ', 'World'; ?>

Code execution result:

Hello World

Example

Outputting variables:

<?php $name = 'John'; $age = 25; echo 'Name: ', $name, ', Age: ', $age; ?>

Code execution result:

Name: John, Age: 25

Example

Usage with HTML tags:

<?php echo '<b>text</b>'; ?>

See Also

  • the printf function,
    which formats and outputs a string
byenru