Note: This is only the release date for Decade Creations.com. This tutorial was released before this date. It is also the date of the new version of this tutorial, it should be easier to read and you should get the same results. It now includes an example file that you can download.
Okay first off this tutorial will be very basic. Okay first you need to know how to start off your php file. Start by opening a php file. If you do not have one you can use notepad and just save it as YOUR FILE NAME.php
Okay now to start the php file, it is very simple all you have to put in is this:
<?php
To end the script you add this:
?>
There are other ways of starting it such as with out the php in the first tag but I recommend this way.
Also naming different parts of the file is a good thing too so that you know where something starts and stops. This gets handy when you are working with big files. Here is how you do it.
There are a few different ways add comments.
// One line comment # One line /* Multiple lines */
To show a user text in PHP you use a thing called echo. You can display normal text and HTML.
<?php echo 'This is where you text and/or html would go!'; echo "More stuff. If you use these you can have variables in here too!"; ?>
You can use '' around your text or "". If you use "" you can display variables between them.
Variables are done as followed:
<?php $variable_name = 'a value'; ?>
The dollar sign must go in front of the name of the variable. Now say you would like to display this variable.
<?php $variable = 'example'; echo 'This is how you add a variable while using this style ' . $variable; echo 'Want text after the variable? ' . $variable . ' Like this?'; echo "With these its just like this $variable"; ?>
Sometimes there can be a problem if you are using ' or " inside your echo or anything else that is surrounded by '' or "" because the script will think that is when it is suppose to end and will give you an error.
In order to fix that you add a backslash before it:
<?php echo 'Shouldn\'t break!'; echo "Shouldn\'t break!"; ?>
Now, We'll take a little look at if statments.
As you advance in programming you will find out you use these lots to do different things.
For this tutorial we'll use a simple situation where you want the user do go to different pages.
Say you a link to go to page.php?location=example
<?php
// This is requesting the variable from the URL
$location = $_GET['location'];
// If statement checks to see if the location is example
if ($location == 'example')
{
echo 'Yes it is example';
}
// No?
else
{
// Its not so we do this:
echo 'Its not.';
}
?>There are different variables that are defined already $_GET is one of them. In this case we are defining the variable $location to equal what ever the location item in the url is. Then we are checking if location equals example. If it does we echo out some information. Then we use the else condition to say if its not equal to example we will echo out something else.
That's just a very basic look at PHP. I hope you've learned a bit. Try playing around and see what you can do with it.
Like This Tutorial? Join the Community Today!













