An Introduction To PHP

PHP is a powerful and highly popular language for programming on the web.

PHP is by far the most popular web programming language. It is used by more than 80% [1] of websites to provide text, images, interactive elements, community discussion and many more features. Websites such as Facebook are historically built on PHP. It’s a great choice of language for beginners to pick up as there’s a large community support network, and the learning resources are numerous.

What is PHP used for?

PHP is used across the internet to dynamically construct pages of text and images to deliver rich content and media to users. By using PHP, a website can serve up an almost limitless variety of data, showing uniquely tailored content to each visitor. This provides a far richer experience than static, unchanging pages of content and it can be used for even more complex operations behind the scenes, such as recording user details in a database, running image processing tasks or communicating with other web servers to fetch data from third-party services.

PHP’s possibilities

Functionality such as contact forms, online shopping, community forums, photo upload sites, social networks and more - all of these can be built using PHP as a foundation. It’s an extremely flexible language.

PHP can dynamically construct pages based on input to provide users with information based on their specific tastes.

A user might, for example, select from a drop-down list of items in a shop, and be presented with a detailed description of the selected product, or fill in an email form to contact you directly about a service, bypassing the need to provide your email address on a public website.

What does ‘PHP’ mean?

It is said that the acronym PHP is recursive, and stands for “PHP: Hypertext Preprocessor” - a recursive acronym, which can cause some headaches! A more sensible explanation is that it stands for “Personal Home Page”, originally from a piece of software developed by Danish programmer Rasmus Lerdorf to maintain his own personal site.

These days, PHP is still used to maintain personal homepages. Also business pages, online directories, online shops… the list goes on. It is an extremely versatile language and, while its critics may say it lacks the langauge processing capabilities of Perl, say, or the complexities of C/C++, there’s no arguing that it is a very capable language for use in creating the underlying code and structure of a great number of websites.

Getting Started - What You Will Need

To get the most out of this tutorial, knowledge of any programming language is not a pre-requesite. In fact, I would hope that even those of you with no more knowledge than how to open a web browser and save text files could get something out of this. But, a small measure of HTML know-how will come in handy (knowing how to code simple HTML documents without the use of a WYSIWYG editor like Frontpage, and how to use <form> elements) as well as knowledge of how to set up applications on your own computer, if you want to try running your own PHP development environment.

I would highly reccommend using the text editor Sublime Text to edit your PHP files, although it does require a license fee for continued use. It’s really just a text editor at heart, but one which offers a great deal of useful functionality to code developers. Using this editor, you’ll be able to see PHP keywords highlighted, and other useful “code hints” to aid you on your PHP journey.

Other highly capable PHP editors include PHPStorm and you can even use a free alternative such as Notepad++

Note that I can’t personally vouch for these alternatives, as I primarily use Sublime myself, and find it to be a very capable editor, but everyone has their own tastes when it comes to their development environment.

The Server Environment

Also required is a platform on which to develop your PHP applications. If you’re new to the world of websites and PHP development, I’d reccommend setting up a hosting account with a reliable web hosting company (I’d recommend Clook.net - they’re the lovely people powering this website) and purchase one of their monthly/yearly “Shared hosting” Unix packages - just a basic one will do, it should provide you with all you need to host your PHP files and see the results.

For the more adventurous of you out there, you can set up your own development server on your home PC, which makes development quicker and easier. That’s outwith the scope of this tutorial for now (A future advanced tutorial will cover this), but for now, a good tutorial can be found by searching around on Google for “Apache PHP Windows”, or “Apache PHP Unix” if you’re setting up on a Unix system.

You can also look into bundled installation packages to make setup a lot easier, such as WampServer (which I use myself) or XAMPP.

Learn more…

This covers the very basics of getting started with PHP. There are a lot more problems or situations you’ll encounter along the way which will require further research to solve, but because PHP is such a massively popular language, you’ll no doubt be able to easily find your answer through a quick Google search, and you’ll likely find more than a few links to helpful answers on the website Stack Overvlow.

Within each tutorial, I’ve tried to provide a gradual introduction to the subject at hand, starting off simple and then leading on to more complex examples as the tutorial progresses.

These tutorials won’t aim to cover everything though, and they don’t aim to replace the more comprehensive PHP references out there - including PHP’s own, extremely useful, online library available through php.net

[1] source: http://w3techs.com/technologies/overview/programming_language/all

« Previous Article

Robin Metcalfe is a freelance developer based in Edinburgh, Scotland with loads of experience in old and new web technologies. Want to know more?

He is currently available for hire . You can also get in touch via Twitter