"Hey ma...I've just heard that the latest and greatest thing is PHP, so I'm gonna go learn me some PHP and write a web-based game that will rock the world..."
We've all seen it on forum postings, heard it said in circles of developers, and probably the most often, from newcomers to the science ('noobs' as they are often called).
So, what exactly is PHP? Well for starters, if you're looking to write a web-based game that will rock the world, PHP is not the language you need. If however you're serious about writing top class web applications, or highly interactive web sites, then PHP may just be right up your alley.
In this 10 part series, I'm going to take you through the basics of PHP and hopefully give you a taste of what such a versatile language can do. I am not, however, going to preach that PHP is the greatest thing since sliced bread. I'll let you decide that for yourself!
PHP, like any good language, has its strengths and its weaknesses, and like any languages, there are some tasks that it's just not suited for. I have as of yet found fairly few limitations, however, especially in the web environment.
Who am I?
It's only fair that if you're going to listen to me waffle on for the next 10 parts in this series, you know a little bit about who I am and what I do.
My Name is "Peter Shaw" or "Shawty" to those who know me, and for want of a better description, I'm a veteran back bedroom (or Old Skool) programmer, a definite child of the 80's some might say.
Because of this I've grown up in today's technological revolution, and fondly remember hordes of my school friends buying Sinclair ZX-Spectrums, and Commodore 64 home computers, and feverishly rushing home from school to play classic games such as "Chuckie Egg", "Manic Miner" and "Jet Pack Willie".
I myself was an Acorn person (apologies to most of you non-Brits reading this who may not know what an Acorn machine was) and spent countless hours learning to program BBC Basic and 6502 Machine code.
As technology progressed I worked my way up through the ranks, with my first introduction to Windows Programming around 1990 using "Windows 3.11 for Workgroups" and previous to that exploring the new up coming phenomenon known as "Linux".
I'm not going to bore you any further with the grizzly details, but I first discovered and started to use PHP about version 3.0, and while I had been aware of it previous to that, I'd not given it any serious thought. That was beginning to change!
Ok, we know about you, what about PHP?
PHP was originally a pet project written circa 1994 by Rasmus Lerdorf as a way for him to count how many people where viewing his web-based on-line CV. Rasmus released the first public version sometime in 1995 where he had an interested following in the open source community that assisted him in improving and fixing bugs in the system.
By mid to late 1995, Rasmus had added a web forms interpreter and MySql library code to his project to accommodate the growing need for storage and processing of data received in HTML forms. This proved that there was a need for a system that could handle this kind of task and Rasmus released the next version now called "PHP/FI" which stood for 'Personal Home Pages Forms Interpreter'. The open source project went from front to back and by 1997 Zeev Suraski and Andi Gutmans had joined the team. They then did a major rewrite of the main core, to form the basis of PHP3. The project was subsequently renamed "PHP Hypertext Pre-Processor", and went on to become the current PHP versions we know today.
So how does PHP Work?
PHP in itself is a very simple system. It works very much like Java does in terms of byte code, but rather than compile once and deploy, the PHP interpreter compiles each time the script or code is run.
Essentially PHP is an interpreted language much like bash shell programming, but it is also a compiled language much like C or C++. This means that the language is both extremely portable, yet it is also very fast to execute.
The best thing about PHP however, is not how the PHP engine compiles it, but how it's actually employed in the world of HTML and web pages. PHP code can be integrated directly into your HTML--all it takes is for the file extension to be renamed to .php and the code to be enclosed in PHP tags as follows:
When saved to a web server and run, the output will show a regular HTML page, with a heading 1 size element that says "Hello World" and a page title of "My Page". The first thing you'll notice if you view the page source is that the PHP code has vanished and that the output is plain HTML. This is a very important concept to remember.
Most languages have to have some form of output where the results can be displayed. For Microsoft Windows and most modern versions of Linux these days, this is the Desktop GUI environment with its point and click interface. For those of you (like me) who are command-line junkies, this will be a standard Console output usually in your default terminal colours.
In the web environment, PHP's output is via your browser's display. This means that there are some things that are not fully possible, but it also means that some very eye catching and colourful displays can be produced by combining nice graphics and good CSS concepts.
As you can see, PHP has a good track record and has the capability to make standard web pages come alive. In the next article in this series, we'll look at what you need to start developing in PHP and how to set it up both under Linux and Windows.
Until next time, remember, programming is not about following text books, it's about experimentation and frustration. Above all however, it's about having fun while learning something new along the way.
If you have any comments or ideas on this series, please don't hesitate to make them known via the comment form below and I'll see what I can do to accommodate them!