PHP Basics Workshop

Developed by: Paul Burney

 
 
 

Sections





<-Prev-    -Next->

Language Syntax

To add PHP code to a web page, you need to enclose it in one of the following special sets of tags:

<? php_code_here ?>

OR

<?php php_code_here ?>

OR

<script language="php">
php_code_here
</script>

So, what kind of code goes where it says php_code_here? Here's a quick example.

<html>
<head>
<title>My Simple Page</title>
</head>
<body>

<?php echo "Hi There"; ?>
</body>
</html>

If you copy that code to a text editor and then view it from a web site that has PHP enabled you get a page that says Hi There. The echo command displays whatever is within quotes to the browser. There is also a print command which does the same thing. Note the semicolon after the quoted string. The semicolon tells PHP that the command has finished. It is very important to watch your semicolons! If you don't, you may spend hours debugging a page. You've been warned....

A little more information can gained by using the PHP info command:

<html>
<head>
<title>My Simple Page</title>
</head>
<body>

<?php phpinfo(); ?>
</body>
</html>

This page will display a bunch of information about the current PHP setup on the server as well as tell you about the many built in variables that are available.

Please note: Most server configurations require that your files be named with a .php3 extension in order for them to be parsed. Name all of your PHP coded files filename.php3.

In the next section, we will discuss using your own variables.