Introduction: Learn How to Program PHP Style

Tutorial: PHP Tutorial - the Basics
Author: laconix / inevitable_chaos
Difficulty: Easy
Description: Just the bare essentials to get you started in PHP.
Prerequisites: Basic html knowledge, a web server with PHP installed.

Step 1: The Basics

BASICS:

Okay to get started create a basic html page like such:
<html><body></body></html>
Okay you're familiar with this no doubt, now to add in the PHP.
<body><?phpecho "Hello World!";?></body></html>
All this simple code does is echo Hello World onto the page.
The 2 most used commands to output information in PHP are print and echo.

Step 2: Variables

VARIABLES:
Have your code set up like before-hand.
<body><?php?></body></html>

To define a variable in PHP a $ precedes the variable name. For example.
<body><?php$hw = "Hello World!";?></body></html>
Now a variable by itself doesn't do anything really, you need to do something with it!
<body><?php$hw = "Hello World!";echo $hw;?></body></html>
All this bit of code does is store Hello World! in a variable called $hw, then echos "Hello World!" onto the page.
If all went well it should look like this: Hello World

Step 3: Statements

Statements:
Okay now we're getting a little more difficult!
Start off with a basic PHP model.
<body><?php?></body></html>
Now add in code to make the variable $pie and $number, and store the string "I like pie!" and 1 in them respectively.
If you got it right it should look like such:
<body><?php$pie = "I like pie!";$number = 1;?></body></html>
Now for the slightly more difficult part, an IF statement.
<body><?php$pie = "I like pie!";$number = 1;echo "Who likes pie?";if ($number != 1)    echo "You didn't store the right number in the variable $number!";else    echo "<br>" . $pie; ?></body></html>
Okay I should now explain the basic operators in PHP.
"!=" - does not equal
"==" - does equal
">" - greater than
">=" - greater than or equal to
"<" - smaller than
"<=" - smaller than or equal to

To separate things in an echo us a period "."

The basic IF statement is structured as such:
    do thiselse    do this

If all went well it should look like this: Statements

You have just learnt the basics of PHP, go and play around with your new learnt skill.

Copyright laconix - http://deadestsystem.info