PHP Echo Tutorials
×

PHP Echo Tutorials

4324

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

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.

PHP Echo 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



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
  1. Manisha Jan 22, 2019

    Nice Code.. Really helpful.