Eastern Michigan University EMU HOME
 
people.emich.edu
About people.emich.edu
Tips & Resources
Print this page
people.emich.edu

Introduction to PHP: Getting Started

PHP scripts are like HTML files, but instead of .htm or .html extension, they are given .php extension. Within the file, PHP code is contained in <?php ?> tags.

Let's take a look at a very simple PHP script, that displays "Hello, World!" in the browser window.

I have put the following in a text-only file called example1.php, and uploaded the file to the server.

Example 1: "Hello, World!"

	<html>
	   <head>
	      <title>Example 1</title>
	   </head>
	   <body>
	   <?php
	      // Say Hello!
	      echo "Hello, World!";
	   ?>
	   </body>
	</html>

See Example 1.

When we view the source of Example 1 in the browser, we notice the following.

  1. Because the page is rendered on the server before it hits the browser, the browser does not see the PHP code.
  2. The entire <?php ?> tag is replaced by the output of the code.
  3. Line 7, which begins with two slashes, is a comment.
  4. Every PHP statement ends with ;

Next: A Useful Example




EMU Home | Contact EMU | Site Map | Directories | Calendars | My.emich | Search