PHP Echo Tutorials

by Anu Gaba 24-Nov-15

1 1256


In PHP, the two basic constructs are used to get outputs which are echo and print. Actually, echo is not a kind of function, it is a language construct, hence, you can use it with or without parentheses such as echo or echo().

The echo means outputting the text to the browser. Throughout, your PHP practice you will be using the echo command more than any other command of PHP. So let's start to output the text in a proper way.

PHP Echo Tutorials

To print a string by using the PHP echo command you can place either a string variable or you can use the quotes, like we do below, to make a string that the echo function will display.

For Example:

<?php

$myString = "Hello!";
echo $myString;
echo "<h5>I love using PHP!</h5>";

?>

Result:

Hello!

I love using PHP!


In the above example, we get the string "Hello" without a hitch. The text we are outputting is being sent to the user in the structure of a web page, so it is essential that we use proper HTML code.

In our second echo statement, we use echo to print a valid Header 5 HTML statement. To do this, we easily put the <h5> at the starting of the string and closed it at the end of the string. Just because you are using PHP to develop web pages does not mean you can forget about HTML code.


PHP echo is use for print the program on server. echo and print almost are same, but echo return value is zero and print return value is 1.

Example:

<?php
echo "I am using PHP";
?>

Result: I am using PHP

Example:

<?php
$mystring = "Hello Joe. I am:";
echo "$my_string Stephen";
?>

Result: Hello Joe. I am: Stephen


Share:


Discount Coupons



Comments

  1. Manisha Jan 21, 2019

    Nice Code.. Really helpfull.

Leave a Reply