Alright, some time since the last post. This time I'm going to go through a bit about PHP. Once again I write this text by improvising and this is really just a quick glimpse.
PHP (Hypertext Preprocessor) is a programming language designed to create dynamic websites. Most of the popular and even less popular sites use PHP (or in worse case ASP). Good thing in PHP is that it's free, uses extensions and lots and lots of other good stuff. You can find more info from
the net.
You should have some basic knowledge about HTML and programming to fully understand everything, or just read this and start to finally understand something
Before you can start using PHP you have to do few steps:
- Download and install an HTTP server software (we are using Apache)
- Download and install PHP (I use PHP 5) or alternate XAMPP distribution for quick install and simpletons
- If you downloaded the normal PHP, spend some time to configure it (not easy for new people)
Configuring Apache:
There's some things to change in the default configuration. Often there can be some differences and unlogical problems in installations but you can always ask for help (I'm here).
Testing the installation:
Create index.php file in the website root directory and copy next lines into it:
<html>
<head><title>Test</title></head>
<body>
<?php
phpinfo();
?>
</body>
</html>
Then open your browser (God, I hope it's Opera) and open
http://localhost/ to test whether the installation was successful. The page should show all info about your PHP installation and modules etc.
Some basic stuff about PHP:
PHP code is written in plain text and is always executed before the data is sent to the client. As you might noticed, the PHP code which you want to execute is always included in between special tags (<?php and ?>). PHP can also include external files. I do this for example to separate database functions, file parsing, texts and page drawing in different files, which are included only when needed.
PHP resembles some other programming languages, like C++ or Java. All variables are prefixed with dollar sign ($) like you'll see in the code below. You can use loops, functions and other familiar stuff. It helps quite a lot if you've done programming and/or web design earlier.
Example page:
Below you see three (3) different codes for php files. File
index.php contains only two lines of code to include other files. Files
head.php and
body.php contain HTML and PHP mixed. Take some time to understand them because I couldn't be less arsed to explain in detail. Finally save all of the files in the same website directory.
index.php:
<?php
include 'head.php';
include 'body.php';
?>
head.php:
<html>
<head><title>
<?php
$title = "This is title text";
echo $title;
?>
</title></head>
body.php:
<body>
<h1>Header</h1>
<table>
<?php
// make ten table rows
for ($i = 1; $i <= 10; $i++)
{
echo "<tr><td>Row $i<td>Cell for row $i!";
}
?>
</table>
</body>
</html>
End words:
I hope you got some idea about PHP. I'm not going any deeper into the programming, but you can find a lot of tutorials in the net and perhaps read a book or two. Keep practicing and you'll gonna get friggin' good in this.
-J-