background
|
|
Computer

Linux
Linux Support
A small area on the internet for Linux Support.
More icon
|
|
Up Image
Navigation
Search this Site
Enter your search terms

Site Breadcrumb - You are here
|
PHP from the Ground Up

Page 2 — What Is It?

So, what is this whole PHP business all about?

PHP is a program that gets installed on top of your Web server software. It works with versions of Apache, Microsoft IIs, Netscape Enterprise Server, and other server software packages.

You use PHP by inserting PHP code inside the HTML that makes up your website. When a client (anybody on the Web) visits a Web page that contains this code, your server executes it. That's why you need to install your own server in order to test PHP locally — the server is the brain here, not your browser. Users don't need any special plug-ins or anything to see your PHP in action — it gets to the end user as regular old-fashioned HTML. The experts tell me that PHP is nice because it does not put a big strain on your server's CPU. (I like it because it makes me feel smart.)

PHP is a scripting language, like HTML. That means that code does not need to be compiled before it gets used — it gets processed on the fly as necessary.

Before we dig in, you should know about a site called PHP.net. PHP is an open-source language, and PHP.net is its control center, with extensive reference material about the language and tips sent in by users across the globe. PHP.net has exceptional, deep information about the language, but it can be a little cryptic for the newcomer. We'll look more closely at how to use PHP.net at the end of this tutorial.

So, what kinds of things can PHP do? Welllll ... it can:

  • take info from Web-based forms and use it in a million ways (store it in a database, create conditional pages depending on what the forms said, set cookies for later, send email, write your mom on her birthday);
  • authenticate and track users;
  • run threaded discussions on your site;
  • serve different pages to people using different browsers or devices;
  • publish an entire website using just a single layout template (server-side includes-style);
  • serve XML pages.
Plus, it can display either the clown or the chicken man depending on which box you check:

Do you want to see the chickenman?
Yes!
No! Show me the clown.

But before we can get to the specific uses of PHP, we need to start with a quick preview of the building blocks of PHP, beginning with a sample script. This example script is titled "chickenman.php." When called by a Web browser, it would simply read, "I am the CHICKEN MAN!"

<?php

print ("I am the CHICKEN MAN");

?>

Everything in red is the PHP code, the black is a string of text that you're telling it to "print," as in "display on a Web page," not "print this on a printer."

The <?php and ?> tags start and end a PHP script, and your meat goes in the middle. Got that? Good! Now let's walk through the basic rules you need to know to before you can write your first PHP script.

next page»