No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

Rechercher une fonction PHP

echo

(PHP 4, PHP 5, PHP 7)

echoOutput one or more strings

Description

echo ( string $arg1 [, string $... ] ) : void

Outputs all parameters. No additional newline is appended.

echo is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function. Additionally, if you want to pass more than one parameter to echo, the parameters must not be enclosed within parentheses.

echo also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. Prior to PHP 5.4.0, this short syntax only works with the short_open_tag configuration setting enabled.

I have <?=$foo?> foo.

The major differences to print are that echo accepts an argument list and doesn't have a return value.

PHP: echo - Manual Home of Manuel PHP  Contents Haut

Parameters

arg1

The parameter to output.

...

PHP: echo - Manual Home of Manuel PHP  Contents Haut

Return Values

No value is returned.

PHP: echo - Manual Home of Manuel PHP  Contents Haut

Examples

Example #1 echo examples

<?php
echo "Hello World";

// Strings can either be passed individually as multiple arguments or
// concatenated together and passed as a single argument
echo 'This ''string ''was ''made ''with multiple parameters.'chr(10);
echo 
'This ' 'string ' 'was ' 'made ' 'with concatenation.' "\n";

// Because echo does not behave like a function, the following code is invalid.
($some_var) ? echo 'true' : echo 'false';

// However, the following examples will work:
($some_var) ? print 'true' : print 'false'// print is also a construct, but
                                            // it behaves like a function, so
                                            // it may be used in this context.

echo $some_var 'true''false'// changing the statement around
?>

PHP: echo - Manual Home of Manuel PHP  Contents Haut

Notes

Note: Because this is a language construct and not a function, it cannot be called using variable functions.

Tip

A benefit to passing in multiple arguments over using concatenation in echo regards the precedence of the period operator in PHP. If multiple arguments are passed in, then parentheses will not be required to enforce precedence:

<?php
echo "Sum: "2;
echo 
"Hello ", isset($name) ? $name "John Doe""!";

With concatenation, the period operator has a higher precedence than both the addition and ternary operators, and so parentheses must be used for the correct behaviour:

<?php
echo 'Sum: ' . (2);
echo 
'Hello ' . (isset($name) ? $name 'John Doe') . '!';

PHP: echo - Manual Home of Manuel PHP  Contents Haut

See Also

Find a PHP function

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-echo.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : http://php.net

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut