|
|
|
|
|
|
PHP Basics
(Editor's note: Intranet Journal is re-running some of our popular tutorials. This one was first published in February.)
This introductory article on PHP will explain what PHP is, how it works, and how you can get started using it.
PHP (Hypertext Preprocessor) is an open source, server-side, HTML embedded scripting language used to create dynamic Web pages. PHP script is embedded within a HTML document and the programmer can jump between HTML and PHP seamlessly within the document while the code remains inaccessible to users since it is processed on the server. It combines the power of CGI scripting with the ease of working within HTML.
PHP offers several key advantages:
Assuming you have an operating system and Web server setup on your server, PHP installation is fairly easy. Essentially you need to install the PHP processor and have your server associate .php files with it. PHP.net has detailed installation instructions for UNIX/Linux, Windows, and Mac OS on its Web site.
Once you have PHP installed, all you need to do is place your php files in your Web directories and the server will automatically parse them when someone points their web-browser to that page.
Getting Started with PHP Pages
The one thing that holds true regardless of the technology you work with is this: the infamous "hello world" is the way to get started. In PHP, our "hello world" would look as follows:
The beauty of PHP is that you can jump in and out of PHP coding using these tags within your HTML. Like with all text-based code, use a text editor (not a word processor) for best results.
If you wish to see all your PHP system information and configuration details, add the following line to the PHP file you created above:
<?php phpinfo(); ?>
As you would expect, PHP has a complete syntax all its own. From variables to operators to built-in functions, it is pretty much the same as anything else - refer to the reference manual until it becomes second nature. For my next few examples I will be assuming basic web programming knowledge, so if you need to reference something, refer to the complete online manual for PHP at: http://us2.php.net/manual/en/index.php
A Quick Form
Let's face it; forms are the cornerstone of almost all web interactivity. As such, let's explore some very basic form processing with PHP to get the hang of it.
First you create the HTML form and call it form.html
If you are familiar with writing CGI to process your forms, you can see that the HTML side is almost identical with the <form action="form_process.php" method="post"> being the critical piece. When a user hits the "Send" button, it calls the .php file entitled form_process.php. This is the file that will be able to capture the input the user entered into the form and "do" something with it (e-mail, display on a page, etc.).
Let's assume form_process.php is designed to display the user's comments on a Web page. The script would look like:
Go to page: 1 2
| |||||||||||||||||||||||||||||||||||||||||||
Intranet Journal's Tutorials |
|
Managing Editor |