Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP echo() Function

PHP echo() Function

PHP String Reference Manual PHP String Reference Manual

Example

Output some text:

Run Example »


Definition and Usage

The echo() function outputs one or more strings.

**Note:** The echo() function is not actually a function, so you do not need to use parentheses with it. However, if you want to pass more than one parameter to echo(), using parentheses will generate a parse error.

**Tip:** The echo() function is slightly faster than print() .

**Tip:** The echo() function also has a short syntax. Prior to PHP 5.4.0, this syntax only worked when the short_open_tag configuration setting was enabled.


Syntax

echo(

strings

)

Parameters Description
strings Required. One or more strings to send to the output.

Technical Details

Return Value: No value is returned.
PHP Version: 4+

More examples

Example 1

Output the value of the string variable ($str):

Run Example »

Example 2

Output the value of the string variable ($str), including HTML tags:

What a nice day!"; ?>

Run Example »

Example 3

Concatenate two string variables:

Run Example »

Example 4

Output the values of an array:

"35"); echo "Peter is " . $age['Peter'] . " years old."; ?>

Run Example »

Example 5

Output some text:

Run Example »

Example 6

How to use multiple parameters:

Run Example »

Example 7

The difference between single and double quotes. Single quotes output the variable name, not the value:

"; echo 'Roses are $color'; ?>

Run Example »

Example 8

Short syntax (only works when the short_open_tag configuration setting is enabled):

Roses are

Run Example »


PHP String Reference Manual PHP String Reference Manual