Introduction
You are about to embark on the journey into web development and the creation of dynamic pages using the PHP server side coding format (hell knows what PHP stands for though...). Enjoy, have fun and tell me if there are any problems.
The Dirty Work
The Basics
What would the world be coming to if I didn't start off with... a "Hello World" script!
"OMFG WTF IS THAT!" I seem to hear you say... well that folks, is a PHP script. Simple, huh? Know, here is what is going on:
|- We always start our code by declaring that we are starting to use PHP, by telling the parser (the server side application processing your code) that we are doing so - "<?PHP".
|- You can comment your code so when you come back to editing the file, or someone else does, you\they know what your doing. The first method is using "//" and then your text. Use this for short comments. If your comment is more then one line long you should use "/*Comment*/".
|- Now you are using a built in function. A function is code that is already written to do a specific task, instead of writing all the code out each time. You can also make your own functions, but that is for a later date. The function we are using is the echo function. This tells the parser to output the given text to HTML. Once we finish the function, we always put a ";" to declare we have done so, else PHP will throw some dodgy errors at you.
|- To tell PHP we have finished writing our code, we must put "?>".
That is it, you have written yourself a script! "What do I do with that?!"... Well, not alot to be honest, but it makes you look good .
Variables
Now, some people have difficulty understanding variables. In actual fact, they are really easy. A variable is a way of storing data, a bit like "x" in a mathematical equation.
Simple!
|- We declare a variable using the dollar sign ($) and then it's name. You can call a variable anything, but they are case sensitive (or am I just being ignorant :confused:) and may not contain special characters (other than and underscore, "_"). We then say that this variable equals something.
|- Now, we tell PHP to echo, or output, the content of the variable we just made.
Great, you now know all about variables!
This is all that will be covered in part one folks, part two will be along soon! Now I will give you a brief summary, plus I will tell you some more stuff.
Summary
You must start and end with <?PHP and ?>.
You can comment your code using // or /* */
You can use HTML in PHP files, either when echoing like "echo "My Text, <br> My other text". That will output the text on two lines. You cannot use <img="blah" /> etc because there are double quotes, and PHP interprets this as the end of the echo function. You should either use single quotes, ' , or none, or end PHP and then start it again like below:
If you don't understand that method - don't worry, just use one of the others.
You can also cancel out special PHP reserved characters (such as the ", double quote) using a slash: / i.e echo "<img src=/"blah.jpg/">"
Variables must begin with a $, are case sensitive, and cannot be reserved names ($_SERVER, $_POST, $_GET, $_SESSION etc. I will tell you more about these in a later chapter).
If you need help with PHP check out http://php.net - PHP is the best documented code around, so use the docs.
You are about to embark on the journey into web development and the creation of dynamic pages using the PHP server side coding format (hell knows what PHP stands for though...). Enjoy, have fun and tell me if there are any problems.
The Dirty Work
The Basics
What would the world be coming to if I didn't start off with... a "Hello World" script!
| <?PHP //This is a comment /*So is this*/ //This comment tells you that below, we are using a function. echo "Hello World!"; ?> |
"OMFG WTF IS THAT!" I seem to hear you say... well that folks, is a PHP script. Simple, huh? Know, here is what is going on:
|- We always start our code by declaring that we are starting to use PHP, by telling the parser (the server side application processing your code) that we are doing so - "<?PHP".
|- You can comment your code so when you come back to editing the file, or someone else does, you\they know what your doing. The first method is using "//" and then your text. Use this for short comments. If your comment is more then one line long you should use "/*Comment*/".
|- Now you are using a built in function. A function is code that is already written to do a specific task, instead of writing all the code out each time. You can also make your own functions, but that is for a later date. The function we are using is the echo function. This tells the parser to output the given text to HTML. Once we finish the function, we always put a ";" to declare we have done so, else PHP will throw some dodgy errors at you.
|- To tell PHP we have finished writing our code, we must put "?>".
That is it, you have written yourself a script! "What do I do with that?!"... Well, not alot to be honest, but it makes you look good .
Variables
Now, some people have difficulty understanding variables. In actual fact, they are really easy. A variable is a way of storing data, a bit like "x" in a mathematical equation.
| <?PHP /*The following code stores text in a variable and then outputs it.*/ $myvariable = "Hello World!"; echo $myvariable; ?> |
Simple!
|- We declare a variable using the dollar sign ($) and then it's name. You can call a variable anything, but they are case sensitive (or am I just being ignorant :confused:) and may not contain special characters (other than and underscore, "_"). We then say that this variable equals something.
|- Now, we tell PHP to echo, or output, the content of the variable we just made.
Great, you now know all about variables!
This is all that will be covered in part one folks, part two will be along soon! Now I will give you a brief summary, plus I will tell you some more stuff.
Summary
You must start and end with <?PHP and ?>.
You can comment your code using // or /* */
You can use HTML in PHP files, either when echoing like "echo "My Text, <br> My other text". That will output the text on two lines. You cannot use <img="blah" /> etc because there are double quotes, and PHP interprets this as the end of the echo function. You should either use single quotes, ' , or none, or end PHP and then start it again like below:
| <?PHP echo "<img src= ?> "blah.jpg" <?php >"; ?> |
If you don't understand that method - don't worry, just use one of the others.
You can also cancel out special PHP reserved characters (such as the ", double quote) using a slash: / i.e echo "<img src=/"blah.jpg/">"
Variables must begin with a $, are case sensitive, and cannot be reserved names ($_SERVER, $_POST, $_GET, $_SESSION etc. I will tell you more about these in a later chapter).
If you need help with PHP check out http://php.net - PHP is the best documented code around, so use the docs.

Also another important one that i always use is includes the php version of lets say iframes XD
<?php
include('afilefilledwithtext.php');
?>
a