PHP Introduction

PHP is a programming language used by various websites to run the backend of contact forms, and many other scripts. PHP can also be embedded directly into mark-up language.

PHP stands for Hypertext Pre-processor. This name originates from the fact that PHP processes all data before it is shown; if you have a contact form, the data will not be sent until all of the information has processed.

Opening and Closing Scripts

At the top of every file you need to do a tag like this:

<?php

And to end every file you need to do a tag like this:

?>

<?php is used to tell the server that you are going to write a PHP script and ?> tells the server that your script has finished. You must include these otherwise your script will not work.

Echo Statement

Functions, in PHP are little bits of code that you use to do certain things. For example scripts like this:

<?php

echo "Hello world!";

?>

This would print Hello world! to the screen. When using the echo function, make sure you include the two speech marks. Put the words that you want to print to the screen between the speech marks. And then put a semicolon at the end. This tells the server that the function is finished.

Using HTML in an Echo Statement

You can also use HTML in the echo function. For example:

<?php

echo "<b>Hello world!</b>";

?>

This would print Hello World! You can use any HTML code in the echo function but there is one thing that you must be aware of.

Using Hyperlinks in an Echo Statement

To use a hyperlink in an echo code, you would need to write something like this:

<?php

//This example is false, continue reading

echo "<a href="http://www.example.com">Hello world!</a>";

?>

This would return an error because you have closed off the speech marks when you placed the URL that you want the text to link to. The best way to get around this is to do a code similar to this:

<?php

echo "<a href='http://www.example.com'>Hello world!</a>";

?>

Comments

If you forget what you have been trying to do you can make comments on your code that the server will not read. They can be done like this:

<?php

//This executes as "Hello World!"

echo "<a href='http://www.example.com'>Hello world!</a>";

?>

PHP, as you now know, stands for Hypertext Pre-processor. This article has covered the opening and closing tags and how to utilize the echo function.