I’m going to start this tutorial with an assumption. I’m going to assume that you, the reader, already have access to a PHP enabled server. My specialization is programming, not server setup, so I’ll leave that part out of this. If for some reason, you DON’T yet have access to a PHP enabled server, or you are wanting to install your own, I recommend hosting with DreamHost. They’re VERY good, offer great PHP server support and are very inexpensive. Click here for more information on how to START building a website.

First off, a little discussion about the nature of PHP. PHP is a server side scripting language, which means that it runs stuff on the server, and returns the results of that process to the web browser of the person who ran it.

Example: When somone on a website clicks “Submit” on a contact form, the server receives the data but doesn’t inherently know what to do with that data. This is where PHP comes in. If the data is submitted to a PHP script on the server, that script can then take that data and email it to someone or stick it in a database.

A PHP script can be as simple as a single line of code to do a math calculation, or complex enough to run an entire website. The format of PHP code is similar to C but in my opinion, is much more forgiving.

A Little About Style

One of the most important lessons to be learned by any coder, even before you really get into much of it, is code documentation. In my opinion, one of the worse problem with many coders is that they don’t know how to document their code. This will be a pain both to you when you want to go back and edit something, and to anyone else who needs to use your code. I can’t say this strongly enough. LEARN TO DOCUMENT ALL YOUR CODE! I’m not talking so much about pages of documentation in addition to the script you are writing. Rather, I’m talking about writing out in the code itself, what you’re doing with each statement or set of statements. You will appreciate it in the future, when you come back to a script and want to figure out what it does, and other programmers who may use your work, will also bless you. It’s also a pretty key factor in getting hired in this industry. If an employer knows what they’re doing, they’re going to have someone look through your code to make sure it’s well formed and not going to cause their other programmers headaches.

Keys to Good Style

  1. In Code Documentation
    As I’ve mentioned above, get in the habit of writing plain text explainations for what you’re doing in the code you’re designing. It’s not difficult to put in a bit of text before a segment of code to explain what you’re going to be doing.
  2. Clear and Appropriate Variable Names
    While coding, you’re most likely going to be declaring variables. (Variables are like boxes of information stored in memory) The more clearly you name your variables, the better off you’ll be later, and the less likely you are to run into conflicts or confusion.

Some Examples

Well, let’s take a look at some PHP Code now so we get the feel for what we’re looking at.

A standard PHP script will be enclosed in tags like this:
# Some php commands here

There are some variations of this as well. For example, some servers will allow you to simply use <? instead of <?PHP. Usually though, it’s good form to use the full <?PHP for clarity.

Now, let’s take a look at some examples of good code documentation and bad code documentation.
Poor Code Style:
<? $x="Some text"; $y="some more text"; $z=$x.$y; echo "Combined text variables = ".$z ; ?>

Better Code Style:

# Declare some text variables
$text_1 = "Some text ";
$text_2 = "some more text";

# Combine the two previous variables into a third variable
$text_combined = $text_1 . $text_2;

# Print out the results
echo "Combined text variables = " . $text_combined;

Combined text variables = Some text some more text

Both of these examples would print out the same result to the browser, but you’ll notice that in the second example, I’ve added line breaks in appropriate places, used more appropriate variable names, and have added comments before each segment of code. (comments are denoted in PHP by a # sign at the beginning of a line) You could even go so far as to add comments to the very beginning of the script, explaining when it was made and what it’s purpose was. See this example…

Better Code Style:


# Sample PHP Programming Script
# Designed Nov. 18, 2005
# Used on "Where to Start PHP Programming" as an example of good
# programming style.

# Declare some text variables
$text_1 = "Some text ";
$text_2 = "some more text";

# Combine the two previous variables into a third variable
$text_combined = $text_1 . $text_2;

# Print out the results
echo "Combined text variables = " . $text_combined;

So what do you think? Still want to be a PHP Programmer? I hope so… It can be a lot of fun.

In the next few tutorials we’ll start going over some of the basic programming structures and commands that you’ll be using as you start coding. You may also find it useful to get a book like the one I’ve recommended at the top of this page. These tutorials will give you the basics and help you to get started, but if you want to get into more complex coding, a book like this one is the way to go.

PHP/MySQL Programming for the Absolute Beginner

** Author’s Note: More tutorials will be coming as soon as I get time to write them. If you have a suggested topic or article that you would like to submit as a tutorial, I’d love to work with you on it.

Related Reading:

PHP for the Web: Visual QuickStart Guide (5th Edition)PHP for the Web: Visual QuickStart Guide (5th Edition)Learn PHP programming the quick and easy way!
With PHP for the Web: Visual QuickStart Guide readers can start from the beginning to get a tour... Read More >
PHP and MySQL Web Development (5th Edition) (Developer's Library)PHP and MySQL Web Development (5th Edition) (Developer's Library)

PHP and MySQL Web Development, Fifth Edition

The definitive guide to building database-driven We... Read More >

Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5 (Learning Php, Mysql, Javascript, Css & Html5)Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5 (Learning Php, Mysql, Javascript, Css & Html5)The fully revised, updated and extended 4th edition of the hugely popular web development book - includes CSS, HTML5, jQuery and the mysqli extension.... Read More >
Filed in: PHP Programming

8 Responses to “Where to Start with PHP Programming”

  1. Van Hinsbergh Says:

    I enjoyed the explainations, now on to the tutorial???

  2. Wayne Says:

    Yes, I was wondering where the continuing tutorial was?


  3. admin Says:

    More tutorials will be coming when I get time to write them. If you have writing ability and a desire to contribute, feel free to contact me.

  4. Wayne Says:

    Ok thanks, I just thought a link was missing.

  5. Nanci Says:

    Being an absolute beginner, I like your style already. Very easy to understand. Thank you for putting your time into this.

  6. Matas Says:

    Your this tutorial is very good and is very easy to understand:)

  7. Jeremy Howe Says:

    Absolutely grand… Easy to see and understand. Thank you for your time on this.

  8. msfitri Says:

    i agree with jeremy its very easy for us to read and understand each phrases.but this tutorial seem end till here..what happen, we need to continue coz all of us are beginner..