CodesJava

Easy learning with example program codes

PHP echo


PHP, also called as HyperText Preprocessor, is an open source scripting language which is used to develop web applications. There are many features of PHP that together contributes in developing websites in an easy, friendly and in an efficient manner.

PHP provides two statements to get output:

  • PHP echo
  • PHP print

PHP echo is not a function or method, hence parenthesis is not necessary with it. It is a language construct output statement provided by PHP to print single and multi line strings, variables, arrays etc. Parenthesis with Echo is mandatory when using multiple parameters simultaneously. The data type of PHP Echo is Void in general, as it does not return any value. This makes it a little bit more faster than PHP Print statement.

Syntax:

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

Example 1: Printing text with PHP Echo statement

<!DOCTYPE html>
<html>
<body>
 
<?php
echo "<h1>Mc Donalds</h1>";
echo "Burger!<br>";
echo "I'm Loving It!<br>";
?>
 
</body>
</html>

Example 2: Printing Variable with PHP Echo statement

<!DOCTYPE html>
<html>
<body>
 
<?php
$txt1 = "Sum of 1234 and 4321 is:";
$x = 1234;
$y = 4321;
 
echo "<h3>" . $txt1 . "</h3>";
echo $x + $y;
?>
 
</body>
</html>
Posted in PHP   
Sign Up/ Sign In
Ask a Question


Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki