Ask most Web application developers their scripting language of choice, and you'll find that most are divided into two camps - the Microsoft Active Server Pages (ASP) folks, and the Cold Fusion users. If you do a little more research however, you'll find there are other options out there, and one of these, PHP 3.0, is in much wider use than one would think for an "alternative product".
January 27, 1999
A recent survey (http://www.php.net/usage.php3) places the number of domains using PHP 3.0 at over 270,000. That's not bad for a completely free scripting language that doesn't even market itself against Microsoft or Allaire.
So what exactly is PHP? At its simplest, PHP is a server-side, cross-platform embedded HTML scripting language. With PHP, you can perform both simple and complex functions with a few lines of additional code. PHP scripting allows you to do everything from "Hello World" popups to database-driven search engines. One of the best things about PHP is that it's totally free, even for those running it on commercial operating systems such as Windows NT.
The PHP scripting language is a hybrid of Perl, Java, and C. Most Webmasters are fairly familiar with at least one of these languages, making PHP a quick language to learn. PHP is very database-friendly, as it can connect to Sybase, MySQL, mSQL, Oracle, and many others (including most ODBC-compliant databases).
PHP code is embedded in standard HTML. Documents must be assigned the ".php3" extension for the interpreter to recognize that they contain scripting. Once the document is properly named, the PHP engine will automatically run the scripts whenever the page is requested.
Looking for an example? Let's begin with the classic "Hello World" code. When a user requests this page, it will be generated as HTML, with the message "Hello World" embedded within it. To the end user, nothing out of the ordinary has happened. They simply requested a page.
First, create an HTML file and name it "hello.php3". Now, input the following lines:
Notice the "<?php" and "?>" tags? These let the Web server know that this is PHP code within the tags, and thus to let the PHP interpreter take over. Pretty effortless, right?
Let's get a little trickier. Let's slap together a form for processing. First, create your form page with the following code inside the standard HTML (and remember the ".php3" extension):
<form action="action.php3" method="POST">
Your name: <input type=text name=name>
Your age: <input type=text name=age>
<input type=submit>
</form>
Next, create another page, named "action.php3". Again, just a standard HTML page but within the code you'll add:
Hi <?php echo $name?>. You are <?php echo $age?> years old.
Now, when the user submits your form, the variable data ($name and $age) are brought over to the results page (action.php3) by the PHP interpreter.
Most work within PHP is really this easy. Database connectivity is as uncomplicated as using Active Server Pages and/or Cold Fusion. PHP has three advantages over the aforementioned scripting languages:
Speed and robustness. Whereas ASP tends to slow down a Web server, PHP rarely suffers from such ills. PHP sites rarely, if ever, bog down under heavy loads (unless the server is already under-powered in general).
Cross-platform. If you're a Linux, FreeBSD, Solaris, Windows NT, IRIX, HP-UX., or Amiga user, you'll find a distribution of PHP.
Ease of use. PHP 3.0 uses a very simple and friendly style of code. Tagging your HTML with PHP scripts is the ultimate in ease, and learning the markup language itself is as effortless as with any other.
If you're a Webmaster in search of a good, easy-to-use scripting language, PHP 3.0 might just be the solution. With such wide (and free) availability, everyone should give it a try. And one last thing...it's Y2K compliant!
Ted Brockwood is the Information Services Manager for a real estate listing service in Oregon. His experience covers Java, Linux, UNIX, NT, Win95/98, Win3.x, and DOS.