Introduction to PHP

PHP is a server-side scripting language usually written alongside HTML. The difference between them is where HTML is interpreted directly by the user's browser, a PHP script is first interpreted by the server, executed, and then sent to the browser along with the HTML. Thus, the server your PHP script is on needs to be able to support PHP; you'll have to ask your host.

PHP code is very different from HTML code, however if you already know HTML then PHP shouldn't be hard to learn. Just like HTML, PHP has tags:

Start Tag End Tag
<?php ?>
<script language="php"> </script>
<? ?>
<% %>


Above are four different styles of tags, but they all mean the same thing. They're telling the server that in between the tags is some PHP code that needs to be interpreted. The top two sets of tags will always work on a server that has PHP enabled, however the last two may not, as they must be enabled seperately by the server administrator.

Now, open up NotePad, or another plain text editor, and let's try our first PHP script. Oh, don't look so worried; it's too easy:

<?php
   print("my first PHP script!");
?>
Here, the print() function will send the data (a collection of characters called a string) between the parenthesis to the browser. Strings must always be surrounded by either single or double quotation marks, however if the data is a number or a boolean (true/false) value, then it doesn't need quotation marks. The semicolon (;) ends the PHP statement.

You can also have all the code on one line, if you prefer, like this:
<?php print("my first PHP script!"); ?>
That's it! Save the file as "test.php" and upload it to your server. It's important that you save it with a .php extension, otherwise the server won't know to interpret the script.

When you call the file in your browser, it should display a line of text that says my first PHP script! If it doesn't, make sure you've named the file with a .php extension, and that your server supports PHP.