Beginner PHP Chapter 1 – The Meet n’ Greet

Imagine this scenario.

You’re a kick-ass designer, you make gorgeous website mocks in Photoshop, and you already know how to turn them into basic HTML websites. The world thinks you’re awesome. Your clients think you’re awesome. You think you’re awesome. And now you want to step up to another level, by learning how to program a website to give it extra functionality. Perhaps you’d like to know how to make login systems. Or you’re looking to make your clients’ websites more secure. Regardless of what your reason may be, having a web-programming skill is a valuable addition to your arsenal of skills.

So what programming code do you choose?

Even among the popular ones, there are several to choose from. You could go for Javascript, which is so closely entwined with HTML that you’ve probably already used it once or twice. You could try C#. There’s also Python and Ruby, which have their own legions of faithful worshippers.You could even abandon your HTML altogether and become a Flash-Actionscript programmer.

However, there is one language that I haven’t mentioned, one that if you start with and if you’re anything like me, you’ll soon learn to love.

PHP.

Introduction

PHP is a server-side scripting language that was created in 1995 by a programmer named Rasmus Lerdorf. Back then PHP stood for Personal Home Page (You were expecting some long, tech-sounding name too, weren’t you?).  It then went through development and improvement in the hands of a few other developers, and in the process acquired its recursive name, PHP: Hypertext Preprocessor (a detailed account of the history of PHP is available here).  It is completely free, and comes with most web hosting packages by default. Currently the latest stable release is PHP5 (specifically, 5.3.2, released on March 4th). PHP6 is also in the making, although there is no release date set for that yet.

Why PHP?

Easy
PHP is a command-line language, which means exactly what it says: all your commands are listed line by line. Think of them as recipes, and you’ll pick it up in no time. To make your life even easier, there are TONS of resources online for PHP coding. Whether you’re having trouble with basic concepts and terminology, or whether you want to know what this particular function does, or even if you want to accomplish some function of your own, there are thousands of PHP-savvy developers out there who share their knowledge and progress with everyone.

Also, PHP’s native error displaying system is extremely useful for helping you debug your codes. You can play with the various settings available to find a setting that suits you. Personally I don’t mind errors popping up here and there, as it draws my attention immediately to a problem I have in my code.

Powerful
You already know that PHP is a server-side language, and that it’s command line, so you know that you have a powerful yet easy-to-use and flexible programming language in your hands. How about I take it one step further and show you PHP’s power over databases? The details of it are extensive enough to warrant their own chapter in these tutorials, so we’ll skip it for now, but with this power you can control information and display it in any way you could possibly imagine. Millions of websites around the world make extensive use of databases and backend systems, so you’ll be gaining an invaluable skill.

Two more facets of PHP’s functions that I should mention here are PHP’s mail() function, and PHP’s file uploading capabilities. Both of these are considered simple enough for beginners to use, and help to give your site massive functionality. Using these codes, you can allow your viewers to upload files, send mails to you or anyone else they choose, or even to get an email whenever someone visits a particular page. However, before you dive into learning how to do those, you should be aware that just popping the codes into your web page is highly insecure, and opens you up for all sorts of spam and viruses. Security aspects of coding, especially related to these two issues, will be covered in another chapter.

No software requirement
PHP doesn’t require any special software to run. You can use anything from Adobe Dreamweaver to Notepad to any text editor that you use. If it can view and edit HTML (and it probably can), then it can view and edit PHP. However, some programs like Microsoft Word will automatically format your quote marks, which is good for writing normal English, but bad for programming. Either turn the autocorrect feature off, or use a regular text editor for your programming.
 
No special requirement
A large majority of web hosting packages will come with PHP software bundled in by default. If it doesn’t, it’s probably available as an add-on to your hosting package for a small fee.

If you feel uncomfortable about using hosting packages and paying extra fees before you know more about PHP, you can always set up a mock server on your computer, using software such as XAMPP or WAMP (several other options exist, so do a little snooping around if you’re curious. If you already know of an excellent one that you think deserves more attention, let me know in the comments!). These mock servers (also known sometimes as localhosts or localhost servers) create a simulated server right on your computer, allowing you to use the code as if it was a server. Almost all the code that you use for live servers can be used for localhost, which makes it an ideal place to train yourself, or to test your codes without waiting for pages to load.

How does PHP work?

Print

An easy way to understand the concept of PHP (or any server-side script) is to think of a layer before your HTML. Something like a preceding filter or brain before your HTML.

Let’s run through an example. Here’s an extremely simple code, designed to show the words “Hello World!” on your browser screen:

<?php echo ('Hello World!'); ?>

The echo function basically displays a string of characters on the screen. In some examples or tutorials you may find print used instead. Don’t worry, it performs the exact same function.

End of Chapter

Since this is the first chapter, you didn’t really learn much more than what PHP actually is. In future chapters, I’ll discuss extra functions, as well as other PHP aspects like variables and classes.

I’m kind of new to writing tutorials, so if there’s something you find here that could have been done better, do let me know in the comments below. Also, if you have any suggestions/requests for future chapters, let me know!

Other posts in the series

  1. Beginner PHP Chapter 4 - Conditional Statements -
  2. Beginner PHP Chapter 3 - Operators -
  3. Beginner PHP Chapter 2 &ndash; Functions and Variables -
  4. Beginner PHP Chapter 1 – The Meet n’ Greet (This post) -
Posted On:
Post Date
16th April 10
Category:
Post Category
Tags
Post Tags
Comments
Post Comments
None yet