PHP echo() Function


The echo() function is used to output one or more strings.

echo is not a function in PHP. Therefore, the parentheses are not required. Both echo "Hello World"; and echo("Hello World"); are valid syntax.
Syntax
echo(strings)
Parameters
  • string - (Required) One or more strings to send to the output.
Printing a string
Example
<?php
  echo "Hello World";
?>

Output

Hello World
Printing Multiple Strings
Example
<?php
  echo "Hi","Hello","Welcome";
?>

Output

HiHelloWelcome
Printing HTML
Example
<?php
  echo "<h1>Hello <u>World</u></h1>";
?>

Output

Hello World

Concatenate Variables and Strings
Example
<?php
  $name = "Ram";
  echo "<br>Hello, ".$name;
  echo "<br>Hello, {$name}";
  echo "<br>Hello, $name";
?>

Output

Hello, Ram
Hello, Ram
Hello, Ram

Prev Next