HomePHP Page 2 - Configuration Manipulation With PHP Config
Plug And Play - PHP
Tired of writing (and rewriting) code to manage your application's configuration variables? Take a look at the PEAR Config class, a PHP toolkit designed specifically for manipulating configuration files and the data within them. This article demonstrates using the Config class to read and write configuration files in XML, PHP and INI formats, and use built-in methods to easily build Web-based application configuration modules.
The Config class is brought to you by PEAR, the PHP Extension and Application Repository (http://pear.php.net). In case you didn't know, PEAR is an online repository of free PHP software, including classes and modules for everything from data archiving to XML parsing. If you need a widget to perform a specific task, and you don't feel like writing it yourself, take a look at PEAR - chances are good that someone's already done the hard work for you.
In case your PEAR distribution didn't include Config, or if you chose not to install the PEAR component, you can get yourself a copy from the official PEAR Web site, at http://pear.php.net/ - simply unzip the distribution archive into your PEAR directory and you're ready to roll!
Very simply, Config provides application developers with a set of APIs that ease the task of reading, writing and maintaining application configuration files. As a tool designed to assist in the manipulation of data, it is capable of producing configuration files in a variety of formats, including Windows INI, XML and PHP formats.
If you're in the business of building Web applications, and if those applications require some amount of configuration to get up and running, you're going to find Config invaluable to your development cycle. Written as a PHP class, Config can easily be integrated into any PHP-based Web application, and can substantially reduce the amount of time you spend manipulating application configuration files and data. You'll find it functional, powerful and (if you're the kind who likes fiddling) easily extensible, and it'll soon be a standard component of every application you write.
There's only one problem with Config - it could do with better documentation. The documentation available on the PEAR Web site is a little too terse for novices, and can throw up more questions than answers if you're coming at it cold. Hopefully, though, the next few pages will help resolve that problem, by illustrating how powerful the class really is with some simple examples.