PHP Echo

PHP echo listed in language construct, not a function. That's why you don't need to use parenthesis with it. But if you want to use more than one parameter, it is required to use parenthesis.

Syntax of PHP Echo is given below

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

PHP echo statement generally used to print the string, multi-line strings, escaping characters, variable, array, etc. Some important things that you must know about the echo statement are:

  • echo is a statement, which is used to show the output.
  • echo can be used with or without parentheses: echo(), and echo.
  • echo don't return any value.
  • You can pass multiple strings separated by a comma (,) in echo.
  • echo is faster than the print statement.

How to print string using PHP Echo

<?php  
echo "Hello World From PHP Echo";  
?>

Output :

Hello World From PHP Echo

Multi line string output using PHP Echo

<?php  
echo "This is example
for multi line string using   
PHP echo statement  
";  
?>  

Output :

This is example for multi line string using PHP echo statement

Printing escaping characters using PHP Echo

<?php  
echo "Hello world \"sequence\" characters";  
?> 

Output :

Hello world "sequence" characters
Note : use backslash ( \ ) to escape the double quote as above example show.

Printing variable value using PHP Echo

<?php  
$msg="Welcome to PHP World";  
echo "Message is: $msg";    
?>  

Output :

Message is: Welcome to PHP World