Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


[CashFX] PHP Tutorial #1 - The Basics filter_list
Author
Message
[CashFX] PHP Tutorial #1 - The Basics #1
[Image: Tl3xIiy.png]
HOSTED BY CASHFX

Tutorial #1 - PHP Basics


So, my first tutorial! Woo! I thought I'd give something back! YAY! This is the way I learned PHP, and I'm stupid. So hopefully, you'll be able to understand it! Biggrin

Anyway, I hate huge intro's, let's just get stuck in Smile

This tutorial does assume that you know basic HTML. I will probably post tutorials on that at a later date, but no promises.

PHP uses a syntax similar to objective C and Perl, however it does look more like Java.

Semicolons
PHP Code:
$i += 15
PHP uses semicolons to end commands. The most common cause of error is simply forgetting to put in a semicolon.
Why are they used? Well, the server would have to try to differentiate the end of one command and the start of another, whereas with semicolons, you tell it. It speeds up the formatting of the page the server will send out (parsing).

The '$' Sign
The $ sign is used across many programming languages, some for different purposes, but is usually quite fundamental. A '$' should be placed in front of a variable. Why? Because, again, it makes the PHP parse faster.
An example of this would be:
PHP Code:
<?php
$stringhere 
"This is some text";
echo 
$stringhere;
?>

Types of variable
So, there are three main types of variables in PHP:
  • String
  • Integer
  • Array
These are the most common, but are not limited - there are other types such as two-dimentional arrays, but for the purposes of what we are going to cover, it's not essential to know others quite yet.

What is a string? Well, a string is a set of characters that are text, such as 'Hello, I'm McDork'. When defining a string, the text should always be enclosed in speech marks:
PHP Code:
$hello "This is my string"

What is an integer? An integer is a number. These don't need to be enclosed in speech marks:
PHP Code:
$mynumber 123

What is an array? Well, let's say you have 5 things you want to store, such as names in the variable $names. You would have to create an array:
PHP Code:
$names = array('Joe''Jack''James''Windox''Peter'); 
These names are now together in one array. You can now call back any name you like by doing the following:
PHP Code:
echo $names[0]; 
- This will return the name Joe.
PHP Code:
echo $names[2]; 
- This will return the name James.
PHP Code:
echo $names[4]; 
- This will return the name Peter.

*REMEMBER* Indexing for arrays start at 0! (Thanks VipVince - my mistake!)

Arithmetic operators.
Now, you will be thinking, I'm not gonna do any math! Oh yeah you are. When handling data, you will always find a situation where you will need to be using some mathematical operator.
Here they are:
  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • % Modulus (division remainder)
  • ++ Increment
  • -- Decrement

If you don't know what any of those words mean, use google. I'm not here to teach maths Wink

There are other types of operator such as Assignment or Comparison operators, however, we will get onto those in later tutorials.

Anyway, if I've bored you enough, I can assure you, that that's it will get better, and you will be able to come up with a functioning website that does quite complex things by the end of this tutorial series.


-Mr. Donuts
[Image: fwFzNUP.png]

Reply

RE: PHP Tutorial #1 - The Basics #2
Thanks for the doughnut!

Loads of people will find this useful, especially beginners.
  • Contact Paradox or Uzi for Admin related duties
  • Contact Operate for Staff queries
  • PM me if you need any help.

Reply

RE: PHP Tutorial #1 - The Basics #3
Thanks for the tutorial bro. I'll need this if I want to enhance my PPD websites lol. I learned how to do the referral link thing though ;D
[Image: rYBC5OE.gif]

Reply







Users browsing this thread: 1 Guest(s)