PHP Echo

PHP echo is a language construct, not a function. Therefore, 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.

The syntax of PHP echo is given below:

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

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

  • echo is a statement, which is used to display the output.
  • echo can be used with or without parentheses: echo(), and echo.
  • echo does not return any value.
  • We can pass multiple strings separated by a comma (,) in echo.
  • echo is faster than the print statement.

PHP echo: printing string

File: echo1.php

snippet
<?php
echo "Hello by PHP echo";
?>

Output:

Output
Hello by PHP echo

PHP echo: printing multi line string

File: echo2.php

snippet
<?php
echo "Hello by PHP echo
this is multi line
text printed by 
PHP echo statement
";
?>

Output:

Output
Hello by PHP echo this is multi line text printed by PHP echo statement

PHP echo: printing escaping characters

File: echo3.php

snippet
<?php
echo "Hello escape \"sequence\" characters";
?>

Output:

Output
Hello escape "sequence" characters

PHP echo: printing variable value

File: echo4.php

snippet
<?php
$msg="Hello rookienerd PHP";
echo "Message is: $msg";  
?>

Output:

Output
Message is: Hello rookienerd PHP
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +