When it comes to playing nice with data in different formats, PHP’s pedigree is hard to beat. Not only does the language make it a breeze to deal with SQL resultsets and XML files, but it comes with extensions to deal with formats as diverse as Ogg/Vorbis audio files, ZIP archives and EXIF headers. So it should come as no surprise that PHP can also read and write Microsoft Excel spreadsheets, albeit with a little help from PEAR. In this article, I’ll introduce you to two packages that make it surprisingly easy to hook your PHP scripts up to a Microsoft Excel spreadsheet and extract the data contained therein. I’ll also show you how to dynamically create a new spreadsheet from scratch, complete with formulae and formatting, and import data from a spreadsheet into a database. So come on it, and let’s get started!
As a developer who builds customized PHP applications for clients on a regular basis, I’m always on the lookout for new and interesting PHP widgets that could reduce the time I spend writing code. And one such widget is PEAR’s Structures_DataGrid package, which provides a handy way to display, sort and edit structured data in a table.
In this second (and concluding) segment, I’ll be giving you a brief glimpse of other aspects of HTML_QuickForm that I think you would find educational, entertaining or both. I’ll be discussing some of the package’s non-standard form elements, teaching you how to combine elements into groups, showing you how to apply templates to control a form’s appearance, and guiding you through the process of writing and registering your own custom validation rules. That’s a lot of ground to cover, so you should stop dawdling over this introduction and flip the page to get started.
This article will introduce you to one of PEAR’s most powerful tools for generating Web forms and validating the input that arrives through them: the HTML_QuickForm package. This package provides a flexible, reusable library of methods that can literally save you hours of time when dealing with form-based user input – and best of all, it’s free and extremely easy to use.
One of the things I like best about PHP, is its support for a diverse array of technologies and formats. Take, for instance, YAML. I’ve been using YAML for a while to manage configuration data for a Ruby-based application, but I recently needed to use it for a PHP-based project for the first time. Although PHP doesn’t come with built-in support for this format, a quick Google search revealed a PECL extension, ext/syck, that allowed me to quickly add YAML parsing support to my PHP build and begin reading and managing YAML-formatted files through my PHP application.
As a community-supported open-source language, PHP enjoys the support of hundreds of dedicated developers, who are continuously adding to the available store of PHP libraries and knowledge. This support is most visible in projects like PECL, the PHP Extension Community Library and PEAR, the PHP Extension and Application Repository, which offers a robust, feature-rich collection of PHP widgets that can save developers a fair amount of time and effort.
One such widget is PEAR’s Pager class, which offers developers a framework for breaking large data sets into smaller chunks, or pages, for greater readability or easier navigation. Pagination is important, particularly when dealing with result sets containing hundreds or thousands of items, because it allows the user to exert some degree of control over which segment of the data set is visible at any given point, and thus avoid drowning in a never-ending sea of data.
Vikram Vaswani is the founder and CEO of Melonfire, a consultancy specializing in open-source tools and technologies. He is a passionate proponent of the open-source movement and frequently contributes articles and tutorials on open-source technologies, including Perl, Python, PHP, MySQL, and Linux, to the community at large. He is the author of four books on PHP and MySQL, including MySQL: The Complete Reference, How to Do Everything with PHP and MySQL and PHP Programming Solutions.
Vikram has more than eight years of experience working with PHP and MySQL as an application developer. He is the author of Zend Technologies’ PHP 101 series for PHP beginners, and has extensive experience deploying PHP in a variety of different environments (including corporate intranets, high-traffic Internet Web sites, and mission-critical thin client applications).
A Felix Scholar at the University of Oxford, England, Vikram combines his interest in Web application development with various other activities. When not dreaming up plans for world domination, he amuses himself by reading crime fiction, watching old movies, playing squash, blogging, and keeping an eye out for unfriendly Agents.
PHP too has included support for the ZIP format since PHP 4.x but it was only recently when, idly browsing the PHP manual, I realized that PHP 5.2.0 includes a re-engineered version of the ext/zip extension, one based on the zlib library. Bored and not a little intrigued, I decided to try it out. And over the next few pages, I’m going to tell you what I found.