Hey!
This is for people who wants to learn/understand PHP.
I recommend Macromedia/Adobe Dreamweaver as an editor. If you don't have it or if you don't want to get it, Notepad should be enough.
What is PHP?PHP means
"Personal Home Page Tools". It's a really easy to learn script language which is mainly used for homepages.
It's better if you know the basics of HTML, before you start learning PHP. You can find a very good tut by
Itz Blood [
here].
PHP is a
server-sided language, that means, the server executes the script and it sends you the executed HTML code. Your browser interprets this code and you see the homepage.
PHP is used for dynamic homepages. For example, the most feedback forms, logins and this forum are written in PHP.
".php" is the file extension for PHP files.
How do I use PHP?Before I said that PHP is a server-sided language. That means, your browser can't interpret these files that easily.
You have got two options:
- 1. You use a server which supports PHP.
- 2. You install a local server.
For
option 1, you need to
google for a host. The host must support PHP. If he does not, you won't be able to execute your PHP files. The better hosts cost money, but there are also free-hosters which support PHP. Usually, free-hosters have some downsides, for example bad speed, low traffic etc. But if you just want to test your scripts, free-hosters will be enough.
In
option 2, you can install a server on your own pc. I recommend the
XAMPP-Lite package. You can download it for several os here:
http://www.apachefriends.org/en/xampp.html.
This package installs the newest version of Apache (a popular server), PHP interpreter and several other useful things.
Important note: Apache Server needs port 80, if it's used or blocked Apache won't work until it's free. Further install information is on the XAMPP-site. If you think XAMPP is installed and started, you can type
"localhost" in your browser. If it works, you will see it. Your documents are saved in
"\xampp\htdocs".
However, this was the most complicated step. If you have any questions,
feel free to ask. It's really hard to install PHP on some systems.
The language "PHP"I can tell you that it
won't work if you write something like that: "Hey PHP! Please give me a guestbook with a lot of cool and crazy smilies! If you don't I will tell your daddy (
Rasmus Lerdorf) !!!!11oneoneeleven".

Nope, we have to be much more...
polite. Here i will explain the basics of PHP.
The Structure:You know, the
basic structure of HTML is:
<html>
<head><title></title></head>
<body>
</body>
</html>
At first, you can place PHP code
whereever you want. A dynamic title? Sure. Script in the beginning of the file? No problem. This is a big pro, and the most languages don't support this.
But you have to tell the PHP interpreter that you write in PHP. You can do it like that:
<?php
// any PHP-code
?>
All the code you write between the tags
"<?php" and
"?>" will be interpreted as PHP code.
Second, there are
comments. The interpreter won't interpret them. They can make the code more clearly, but if you use them wrong they can confuse you too. Comments are initialized with "//".
Example:
<?php
// This won't cause an error.
?>
Third, there are
variables. What are variables? Well, they are
containers of data. If you have any data you want to use later, you should use variables. Variables can be words, sentences or numbers. They are initializes with "$".
Important: You have do embed character strings with a
apostroph. Numbers are written
without it.
Example:
<?php
// Example 1:
$string1 = 'Hello';
$string2 = 'World';
$string3 = '$string1 $string2';
// $string3 will be "Hello World".
// Example 2:
$number1 = 2;
$number2 = 3;
$number3 = $number1 + $number2;
// $number3 will be 5.
?>
Basic commands:It would be quite useless if the only thing PHP is able to was to tell the interpreter that there will come PHP code.
One thing: Most commands are ended with a
";". If you don't do this, you will get an error.
Of course there are a great many commands. Here a few:
echo:The echo command is responsible for
outputs. If you want to display a text, use "echo".
Example:
<?php
// Example 1:
echo ('Hello World!');
// you will get: "Hello World!"
// Example 2:
$string = 'World';
echo ('Hello $string!');
// you will get: "Hello World!"
?>
if-else-structures:If-structures mark
conditions. If you want to phrase a condition, you can do it like that:
<?php
// Example:
$name = 'Aizen';
// let's establish a relationship to Bleach xD
if ($name == 'Aizen') {
// if name is Aizen, do something (the double "=" (->"==") is important, it means "Is Equal To"!)
echo ('Welcome home, Aizen-sama!');
} else { // else do something
echo ('Welcome to this homepage, stranger!');
}
?>
After the "{" and "}"
isn't a ";"!
What can I do now?You know...
- ...what PHP is.
- ...how to use PHP.
- ...what variables are.
- ...a few structures and commands.
Of course, you can't program great homepages with this, but this are the basics, and you will use them very often if you use PHP.
More may come later.
Kael