image of customised PHP logo

intro...

In its earliest version called "Personal Home Page" - PHP stands for "PHP Hypertext Preprocessor" - it is a so-called "interpreted programming language". PHP processes hypertext, such as HTML, before it leaves the webserver and displays the result in the browser window. This function allows you to use dynamic content within your site as well as allowing you to create a structure for it which makes any relevant edits and future updates much more efficient and less time-consuming. PHP code was developed for embedment within HTML and is compatible with all platforms and all types of browsers which makes it almost universally accessible.
PHP is open source and free to download, install and use - have a look the official PHP site for more information: uk.php.net. To understand the main strucure and syntax - go through the introductory tutorial and make sure to read through the user comments.

PHP is a server-side scripting language which means you will need to upload any php files to a server - this can be a local server on your computer or network or a remote server - in order to be viewed and tested. Any webpage using PHP needs to have the relevant file extension - most commonly being .php. The scripts will be executed on the server and the file then returned to the browser as HTML.

Any block of PHP script can be written in its own file containing php alone or within an HTML file - it starts with <?php and end with ?> - as shown below.

<?php

?>

In order to learn PHP you will need to ensure that you have access to a script-enabled server. As PHP is very common most hosts offer its support but you will need to check whether it is already installed and ready or whether you will need to do this yourself. Please refer to the official manual: Installation and Configuration

image of figure

To start off with - try out the classic first programmer's line: "Hello World ". The following script will send the 2 words via PHP to the server - the PHP script will then process the file and return it to the browser as HTML. The file then gets displayed as any other file - showing the text using the browser's default settings, as shown here.
As most of us will use our online server - these steps will involve uploads and online testing only.

<html>
<body>

<?php
echo "Hello World";
?>

</body>
</html>

Looking at the code you will notice that we have both HTML and PHP within our file. In order to be processed correctly however - the correct file extension (.php) needed to be used.
You will recognise the syntax structure with its opening and closing tag and, as with many other scripting languages, each instruction is completed with a semicolon at the end of the code line.

The above example did not require the use of PHP - to display the 2 words within our browser window this could have just as easily been written as HTML- as in this case we are dealing with static content. To involve the PHP processing - we could write the same statement using a variable.

<html>
<body>

<?php
$message = "Hello World";
echo $message;
?>

</body>
</html>

In this example now - the variable name is message and gets processed via PHP to display in exactly the same way as our first example. The difference here however is that this file does need to be processed by the server as it could not have been written in HTML alone. Here, the value (Hello World) of the variable (message) gets processed and passed back to the browser as HTML to rendered for display in the browser window.

To process this code and pass the value onto the broswer echo is being used.
For detailed information - please refer to the official PHP Manual