Skip to main content
Web Development Tutorials

PHP

Basics

"Hypertext Preprocessor (PHP) is a widely used, general-purpose scripting language that was designed for web development to produce dynamic web pages."

The PHP tutorial series aims to take you from the very basics right through to some of the most advanced techniques used within PHP.

PHP is an HTML-embedded scripting language. The goal of the language is to allow web developers to write dynamically generated pages quickly.

PHP.netThe PHP Group

Who uses PHP?

PHP is used by over 80% of the websites on the internet, but here are some of the notable ones.

Installing PHP

Online Installation

Most web hosting companies support PHP because it's free to download. The best way to test this is just to create a basic ".php" page in your web directory and the server will prase it for you.

PHP.net offers a great tutorial on how to install PHP 5 if you need to do so.

Installing PHP
Installing PHP

Local Installation

To run PHP locally you need to install a local server. For this I personally recommend xampp. This will give you an Apache web server with PHP & MySQL - things you would normally get from a web hosting company.

Here are some great videos from Codecourse on installing PHP locally.

Windows

Play Video

Codecourse: Setting up (Windows)

Mac

Play Video

Codecourse: Setting up (Mac)

Syntax

Creating a Page

A block of PHP code must always start with<?php and end with ?>. PHP code can be anywhere in the document as long as the document extension is .php .PHP documents can contain HTML, but it must be within quotes or outside of the PHP tags.

PHP statements must end with ; to signify the end of the statement. This is a common error when beginning PHP. PHP functions are wrapped in { and } brackets to signify the start and end of the function.

White Space

Much like HTML, white space is ignored between PHP statements. As a result of this you can separate lines of code with more than 1 line which you may find helpful when splitting certain parts of your code up. Another common practise in any code is to tab indent your code, this makes it much easier for you to follow what is happening and read back through at a later date.

Comments

Commenting your code is seen as good practise, especially when working on projects with multiple authors. There are 3 methods for writing comments in PHP.

  • // for single lines
  • # for single lines
  • /*comment here*/ for block comments

Subscribe for Updates

Get notified about my latest content first and receive invitations for subscriber only competitions.

PHP Variables