The echo command in PHP is used to output the text in the web browser. And echo is not a function, but it is a language construct. Meaning you don’t need to use a parenthesis with it.
Outputting a string
In outputting a string in PHP, we use echo. We place a string variable or we can use quotes, like what we are going to do in this example.
The code below we output a “Hello everyone!”. And the text we outputting is being sent to the user in a form of web page and it is very important to use a proper HTML syntax.
In the second echo, we simply put the
<h3> tag at the beginning and closed it at the end of the string. Because we are using PHP to make web pages.
- $greetings = "Hello everyone!";
- echo $greetings;
- echo "<h3>PHP programming is fun!</h3>";
Hello everyone! PHP programming is fun!
In echoing variables using PHP is very easy because there’s no quotations are required even if the variable does not hold a string.
- $myFirstName = "I am Manny ";
- $myLastName = "Pacquiao, and i am ";
- $age = 34;
- echo $myFirstName;
- echo $myLastName;
- echo $age. " Years old";
I am Manny Pacquiao, and i am 34Years old
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.