1. Home
  2. Computing & Technology
  3. PHP / MySQL

Learn PHP - A Beginner's Guide to PHP Programing

By Angela Bradley, About.com

3 of 9

PRINT and ECHO Statements

First we are going to learn about the echo statement, the most basic statement in PHP. What this does is output whatever you tell it to echo. For example:

<?php echo "I like About" ?>

This would return the statement I like About. Notice when we echo a statement, it is contained within quotation marks [“”].

Another way to do this is to use the print function. An example of that would be:

<?php print "I like About" ?>

There is a lot of debate about which is better to use or if there is any difference at all. Apparently in very large programs that are simply outputting text the ECHO statement will run slightly faster, but for the purposes of a beginner they are interchangeable.

Another thing to keep in mind is that all of your print/echoing is contained between quotation marks. If you want to use a quotation mark inside of the code, you must use a backslash:

<?php print "Billy said \"I like About too\"" ?>
When you are using more than one line of code inside your php tags, you must separate each line with a semicolon [;]. Below is an example of printing multiple lines of PHP, right inside your HTML:

<html>
<head>
<title>PHP Test Page</title>
</head>
<body>
<center><b>
<?php
print "I like About";
print "<br>";
print "Billy said \"I like About too\""
?>
</b></center>
</body>
</html>

As you can see, you can insert HTML right into your php print line. You can format the HTML in the rest of the document as you please, but remember to save it as a .php file.

3 of 9

Index: Learn PHP - A Beginner's Guide to PHP Programing

  1. Basic PHP Syntax
  2. Comments
  3. PRINT and ECHO Statements
  4. Variables
  5. Arrays
  6. Operands
  7. Operators
  8. Conditional Statements
  9. Nested Conditionals

Explore PHP / MySQL

More from About.com

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Learn PHP
  5. Learn PHP - PHP Tutorial - Print Echo

©2008 About.com, a part of The New York Times Company.

All rights reserved.