Welcome to the first in our series of PHP beginner tutorials for web designers. When you are finished with this, why not check out the Javascript and Actionscript tutorials as well.
We’re going to start at the very beginning, and I’m going to try and keep it as simple as possible, as I know how confusing it can look.
What is PHP?
PHP stands for PHP: Hypertext Preprocessor. It is a widely used server-side scripting language that is particularly suited to web development. PHP allows you to take a normal HTML web page and make it fully dynamic; on top of that you can also create dynamic javascript and CSS files with PHP.
Where to Start
To start using PHP you will need a server that has PHP enabled. You can also install local environments with PHP enabled, called MAMP (for Mac), or WAMP (for PC). You will also need to make sure that any files where you are using PHP end with the .php extension. These days, most web hosts support PHP, but it is best to find out beforehand – to save yourself from tears.
Your First PHP Enabled Page
To create your first PHP enabled page, you will of course need some sort of editor. There are a tonne of editors available, but I find myself using Adobe Dreamweaver.
So, open your text editor and add the following code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>My First PHP Page (Hopefully)</title> </head> <body> <?php echo '<p>Hello World!</p>'; ?> </body> </html>
Save this file as helloworld.php and upload it to your server. This is PHP in its simplest form; if PHP is enabled on your server, then when you browse to this file on your server you should just see Hello World! displayed as a simple paragraph.
PHP has many “functions” and “language constructs” built into its library, and in this case we are using a language construct called echo(). When using functions it is necessary to use parentheses, however – you will notice as we go on that with language constructs, they are not often needed. All the echo command will do, is output a string of text to your web browser; this is probably the most used PHP command.
Final Words
I think we’ll leave it there for today, you have learnt a bit about what PHP is, where to write it, how to save it, and also – how to write it…. kind of!
Tune in for the rest of this series where I will be covering much more of PHP including more advanced stuff like arrays, functions and variables.
11:19 02/02/2011
Nice introduction to PHP, perfect tutorial for someone who is starting to learn PHP – like myself! I can’t wait to see future tutorials. Can you explain to me the difference between Print and Echo as I have seen these used for similar things, but I’m not sure which situation is best to use each one.
Cheers for now.