Page 480 - Beginning PHP 5.3
P. 480
Part III: Using PHP in Practice
In this chapter, you look closely at PEAR, and learn how to install and uninstall PEAR packages. You
explore some useful packages by writing some simple scripts that use them. By the end of the chapter,
you ’ ll have written applications that can:
❑ Detect the user ’ s browser
❑ Generate HTML tables using pure PHP code
❑ Create, validate, and process Web forms
In each case, you use PEAR packages to do most of the hard work, freeing you up to concentrate on the
application ’ s logic. By the end of the chapter you should have a good appreciation for the power of
PEAR packages, and of reusable code in general.
Installing PEAR Packages
To use a PEAR package, you need to install it on the same Web server as your PHP installation, so that
your PHP scripts can access it. Installing a PEAR package is easy, thanks to the PEAR package manager
that comes bundled with your PHP installation. The first thing to do, though, is find the name of the
package that you need to install. You can do this in one or more of the following ways:
❑ You can browse packages by category at http://pear.php.net/packages.php
❑ You can search package names and descriptions at http://pear.php.net/search.php
❑ You can view a full list of packages ordered by popularity — most downloaded first — at
http://pear.php.net/package-stats.php
Once you ’ ve found a package that you want to install, it ’ s time to run the PEAR package manager to
install it. First, though, it ’ s a good idea to test that the package manager is available and working. If your
PHP installation is on Ubuntu or Mac OS X, the PEAR package manager is already installed and
available. On Windows you need to set up the package manager first.
Testing the PEAR Package Manager on Ubuntu
To give the PEAR package manager a test drive on Ubuntu, simply open a Terminal window
(Applications Accessories Terminal) and type:
pear
Then press Enter. You should see a list of commands appear, as follows:
$ pear
Commands:
build Build an Extension From C Source
bundle Unpacks a Pecl Package
channel-add Add a Channel
channel-alias Specify an alias to a channel name
channel-delete Remove a Channel From the List
channel-discover Initialize a Channel from its server
channel-info Retrieve Information on a Channel
442
9/21/09 9:14:47 AM
c15.indd 442
c15.indd 442 9/21/09 9:14:47 AM