PHP Tutorial 1
By James Moran
Creating your first program
1. First of all we need to create a file called program.php. So open up a simple text editor like Windows Notepad. Save the blank file as program.php in a folder ready to upload to your PHP enabled server.
2. Once your file is saved, it is time to start your coding (exciting isn't it!!). The first thing you should always type before typing anything else is:
<?
?>
This tells the browser that the text between these arrow question marks is going to be PHP code and so will run it as such.
Unlike languages like Javascript, PHP coding doesn't get displayed in the source code of an HTML page e.g. when a user clicks 'view source' in their browser. This enables you to store data like passwords within the code and be safe in the knowledge that no-one can discover it.
3. Now you are ready for your first command. We are now going to 'echo' some text, which will display some text on the page. So, in between the arrow question marks type:
echo 'Hello World';
So the whole program should look like this:
<?
echo 'Hello World';
?>
Now save, upload and view your program in your browser.
You should see a blank white page with Hello World written on it in black. If so, congratulations, you have written your first PHP program!
Now I will explain what you have just done.
The echo command allows you to output anything onto the screen, whether it is an image, text, HTML.
The single quotes tell the browser that what's between them is what needs to be echoed. The semi-colon denotes that a commend line has ended and to go onto the next line.
Well that's it for your first lesson. Have a cookie.