OK. So now we should go to the folder where the PHP files are stored. If you’ve installed XAMPP to the standard directory, the web folder should be in C:/XAMPP/htdocs. Now make a folder with the name, for example, ‘php’. It’s time to make a first script to test the functionality of PHP.

Step 1: start Notepad++ (or any other text editor you want to use)
Make a standard HTML page, like the one below (it’s not necessary by the way):
<html>
<head>
<title>Test page</title>
</head>
<body>
</body>
</html>
Now, between <body> and </body>, put the code provided below:
<?php
echo “Hello world!”;
?>
A PHP script always starts with a ‘<?php’ tag and always ends with a ‘?>’ tag. The echo statement brings the text you typed between the double quotes to the screen. A line of PHP code mostly ends with a semicolon (;). Now let’s save our script and test it. Go to the folder ‘htdocs’ and save the file as, for example, test.php in the folder you’ve created (in my case the folder ‘php’). Now lets test it. In your browser type ‘http://localhost/php/test.php’. You should see a web page with ‘Hello world!’ on the screen now.

Let’s talk about variables now. This is very important in programming in PHP (and not only in PHP, in all programming- and scripting languages). Variables can store data, data collections and many more things for you to call it later on. Let’s explain it with a piece of code (make a new file or type this in your existing file):
<?php
$name = “Duco”;  //PHP variables always begin with a dollar sign.
$age = 19;   //Number variables (integers) don’t need double quotes, text (strings) do.
echo “Hello, my name is “.$name.”, and I’m “.$age.” years old”;  //I always use dots to seperate plain text from variables, it looks clearer in my opinion.
?>
If you try this in your XAMPP webserver, it will say “Hello, my name is Duco, and I’m 19 years old”. Now play with the values of the variables. Variables are very useful. If you, for example, have to write a date four times, you can store the date in a variable. And if you want to change the date, you only have to do it once.
There are four major types of variables you will use a lot in PHP:
- Integers: numbers (i.e. $number = 16;)
- Strings: text, it varies from one character to whole stories (i.e. $string = “Groningen”;, $string = “B”;)
- Decimal: an integer with a decimal value (i.e. $decimal = 15.41;)
- Boolean: a representation of ‘true’ (1) or ‘false’ (0) (i.e. $bool = true;, $bool = 0;)

Now let’s do some comparations. PHP has some comparison signs to check things.
<: smaller than
>: bigger than
<=: smaller than or equal to
>=: bigger than or equal to
==: equal to
!: not equal to   //for example, !< (not smaller than), != (not equal to)

Now for some code:
<?php
$age = 15;
if($age >= 18)    // If your age is equal to or bigger than 18…
{
echo “You can take driving lessons.”;
}
else
{
echo “You can’t take driving lessons, you’re too young.”;
}
?>
This script will say “You can’t take driving lessons, you’re too young.”. Now change $age to 18. It now will say you can take driving lessons.

You also saw the if-else construction. It’s necassery in any scripting- and programming language. If the conditions aren’t met, the actions written between the else brackets will be performed (by the way, you can’t use ‘else’ if you haven’t used an ‘if statement’ before. You can however use an’ if statement’ without an ‘else’). The open- and close brackets are necessary at each check.

Well, that was the second part of the tutorial. And if things aren’t clear, please say it, because this is my first tutorial.