In this tutorial, you will learn how to use PHP echo statements to print any message in the web browser with the help of examples.
PHP echo statement is used to print strings, multi-line strings, escape characters, array, variable, etc.
PHP echo is a language contract of PHP not actually a function. Therefore you are not required to use parentheses with it. However, if you want to pass more than one parameter to it, you need to use parentheses.
PHP Echo Syntax
void echo ( string $arg1 [, string $... ] )
Some of the important characters of PHP echo are as follows.
- echo is a PHP statement that is mainly used to display output on the web browser.
- PHP echo can be used with or without parentheses i.e.
echo
orecho()
. - You can pass multiple arguments to echo using comma(,).
- It is slower than PHP print.
- echo does not return any value.
PHP echo: printing String
<?php echo "PHP echo by Tutorialsbook"; ?>
Output
PHP echo: printing multi-line string
<?php echo "PHP echo by Tutorialsbook. This is the example of PHP echo multi-line by PHP echo statement."; ?>
Output
PHP echo: printing escaping character
<?php echo "PHP echo by \"Tutorialsbook\""; ?>
Output
PHP echo: printing variable value
<?php $msg="PHP echo by Tutorialsbook"; echo "Message is: $msg"; ?>
Output