Left Quote    Black holes are where God divided by zero.
- Steven Wright    
Right Quote
[login] | [Register]

Introduction to PHP

by: Jester
Page: 1 of 7
(View All)


This tutorial was written to introduce you to PHP, it assumes you know nothing about programming at all, starts with the very basics and slowly guides you through some of the concepts of PHP programming. Hopefully this tutorial will clear up the basics and allow you upside-down people to follow, and I quote, some of my other “too technical” tutorials.


PHP is an ever-popular web scripting engine. It allows you to create dynamic web pages easily and quickly. It has a very rapid learning curve so once you get the basics down you’ll progress very quickly and start writing some nifty scripts. In newbie terms: it’s a thingy that runs in conjunction with a web server that easily allows you to create web pages that change—such as guestbooks, list users’ comments, discussion boards, top fifty lists, administration panels … and so forth.

Yeah ok, so how do I use it?

Firstly you must ensure you have access to a web server that is compiled or set up to work in conjunction with PHP. Most good web hosts these days will offer PHP support, and if they don’t you can always bombard them with e-mails and whine until they do. PHP is getting very popular so the chances are you’ll have access to it. If you don’t you can always install it yourself on your own system, along with a web server. You can find instructions on how to do this, on a wide range of operating systems, in the PHP Manual.

So How Do I write It?

PHP is very simple to use, the first thing to note is that PHP is embedded into HTML. You don’t have to have pure PHP code in a PHP document, you can switch between HTML and PHP, let’s take a look:

Simple, eh? Let’s have a closer look at it. The script starts off as any HTML document would, with a DOCTYPE definition followed by an open HTML tag, title, body tag, the only bit we’re interested in is the stuff between <?php and ?>. That is the PHP code, only when you open the PHP tag, <?php, can PHP code be used.

This is a great feature of PHP as you can just type out HTML if that’s all you need and jump into “PHP Mode” when and if you need it, remember: a PHP document doesn’t have to contain only PHP.

So What Happens?

Remember how I said you need a web server that works in conjunction with PHP? You need this because the PHP code has to be executed, the PHP interpreter handles this. The web server is set up to recognize certain extensions as a PHP document, say .php. here’s what happens:-
  1. Internet browser requests “index.php” from “”.
  2. AllSyntax web server receives request.
  3. Web server checks “what type of document is this?”, oh look ”.php”, it’s a PHP document.
  4. Web server invokes the PHP engine and passes it the contents of “index.php”.
  5. PHP Engine checks the document and anything between <?php and ?> is converted to HTML output.
  6. PHP returns the HTML output to the web server.
  7. Web server sends document to internet browser.

That make sense? PHP code does not have to be compiled (converted to an executable program) before hand, when the web server passes PHP the document, it is then compiled on-the-fly (or interpreted), executed, checked for errors and then returned to the web server. So what is sent to the client (the person requesting the document) is not PHP code at all, it is the output of the PHP code. So … what would they receive from the above program?

All the PHP code did was to output "<p>This is my first PHP script.</p>", when PHP sends the output from the script back to the web server the above is what remains. If a user views the source of a PHP page in a text editor they will not see PHP code, all they will see is the output of that code.


The only bit of the above script we’re interested in is this:-

We opened into PHP Mode, used the echo function (language construct, whatever) to output a sentence, or string. Echo is just for printing stuff out, for example:-

Would output the text “Hello World!”, just type <code>echo 'whatever'; </code>, the string is enclosed in single quotes and after the closing quote is a semi colon (;). We then closed PHP Mode and wrote out the end of the HTML document.

The Point

Well in the above script there really is no point, many a time I have been asked something similar to:

“Why not just print out the '<p>This is my first PHP script.</p>' using normal HTML!?!?”.

“Because this is an example showing you how you go into PHP Mode, how the web server handles the request and what goes on in the background, not a discussion forum, you silly person.”, I answer.

Points To Remember

  1. You need a web server that is working in conjunction with PHP, don’t know if yours is? Ask your host “can I use PHP?”. They said “Nope”? Tell them how much they suck and then install it yourself .
  2. A PHP document doesn’t have to contain only PHP, PHP is embedded into HTML.
  3. PHP code is contained between <?php and ?>
  4. The above script was just an example, an example!

Now that we have that cleared up and you (hopefully) know how PHP works, how to embed it into HTML, (hopefully) have access to a web host that uses it and didn’t fall asleep on your keyboard and are now ready to get coding some PHP. Click “Variables” and learn how to use variables in your PHP documents.

1  |  2  |  3  |  4  |  5  |  6  |  7  |  
Next »


  Subject: "You rocks" Date: Jan 08 2008 at 11:11 am    
Wow that tutorial made the PHP a piece of cake

Many thanks I put !!
  Bob C
  Subject: "Great tutorial" Date: Oct 18 2008 at 6:55 pm    
Many thanks to the author!
  Subject: "Oh Guru" Date: Feb 12 2009 at 1:00 pm    
Excellent. Easy to Learn.Simple Language.

We Need Your Help in all level of career progress.
All the very Best
You Must be logged in or a member to comment.

Tutorial Stats

Tutorial Stats

9 Total Comments
5 Rating of 5 (3 Votes)


Tutorial Options

· Login to Rate This Article
· Login to Post a Comment
· Read more by this author
Digg This Article! Bookmark This Article Reddit: Bookmark This Article BlinkList: Blink This Article! YahooMyWeb BlogMarks: Add This Mark! Furl: Save This Article Spurl: Mark This Article



· Simple PHP Tutorial
· One File Website
· Pagination with PHP
· Building a Comments Script
· Complete Members System
· Variable Scope

"" Copyright © 2002-2021; All rights lefted, all lefts righted.
Privacy Policy