PHP Echo

Submitted by: 
Language: 

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.

PHP CODE

  1. <?php
  2. $greetings = "Hello everyone!";
  3. echo $greetings;
  4. echo "<h3>PHP programming is fun!</h3>";
  5. ?>

Display:

Hello everyone!
PHP programming is fun!

Echoing Variables

In echoing variables using PHP is very easy because there’s no quotations are required even if the variable does not hold a string.

PHP CODE

  1. <?php
  2. $myFirstName = "I am Manny ";
  3. $myLastName = "Pacquiao, and i am ";
  4. $age = 34;
  5. echo $myFirstName;
  6. echo $myLastName;
  7. echo $age. " Years old";
  8. ?>

Display:

I am Manny Pacquiao, and i am 34Years old

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.