You are on page 1of 2

PHP Tutorial 1

(The Basics of PHP)

Intro PHP is the recursive acronym for "PHP: Hypertext Preprocessor" a programming language devised by Rasmus Lerdorf in 1994. Dont ask me why its not called HPP because I dont know. Enough of the boring stuff, lets get to the script it self. PHP is a server side language(the server processes the script not the visitors browser, unlike html) First, first you have to show the server that you are going to use PHP by putting one of the following PHP tags. The script goes inside it. Note that all the examples below are pseudo codes. Example 1: <?PHP Your script goes here PHP?> Example 2: <? This is the most commonly used PHP tag ?> Example 3: <?PHP You can also do a combination of the 2 tags above ?> Example 4: <? It works like this too PHP?> Example 5: <script language=php> This is usually used when you add PHP to an html document. You can use the other two as well. </script> You can use all of them but I prefer the one in example 2 as it is faster to type and easy to remember for people like me who dont want to put too much effort in typing out long PHP tags.

Simple Scripts What I am about to show you is very simple and basic. It shows you how to display text using PHP. To show text using PHP, the tags echo and print are used. As far as I know, both will give you the same results. Example 6: <? echo I love Hoobastank; ?> Example 7: <? print I love Hoobastank; ?>

Both the examples above will display the text I love Hoobastank ;) Notice that at the end of the line, there are semicolons. This is very important. It tells the server that you have finished using the tag (in this case echo & print) If you do not put them, you will get an error. Now I will teach you how to format a PHP text. If you want the colour of the text to be #990000(red), you would put something like this in html. Example 8: <font color=#90000>I love Hoobastank</font> In PHP you will have to add a backslash in front of every inverted comma. The script will be something like this. Example 9: echo <font color=\#990000\>I love Hoobastank</font>;

Well thats it for the first tutorial. I know this doesnt really teach you much but hey, at least you learnt something. In the second tutorial you will learn about variables and statements. Have fun!

You might also like