Working with PHP online script archives

Treasure


As a PHP Programmer, you may occasionally find yourself at a dead end. Discovering the perfect code snippet, script, or class to use alongside your own code can save time and frustration.

By Ken Hess

Dawn Hudson, Fotolia

On the Internet, you'll find dozens of free script archives that let you browse and pluck PHP scripts for your own use. Most of these sites have an array of offerings, from simple scripts, to complete web applications, to full-blown software suites. In this article, I describe sites I visit when I'm looking for a ready-made PHP script.

devshed.com

Dev Shed is the grandaddy of the shared-resource developer communities. The site has a Google ranking of 8 and boasts more than 150,000 subscribers. Now part of the Ziff Davis Enterprise, Dev Shed is the flagship developer community catering to programmers of many languages and technologies. Devshed's main site focuses on articles, tutorials, and the developer community. If it's only scripts that you want, you'll be redirected from the main site to Scripts.com - Dev Shed's code library.

At Scripts.com, you'll see that the PHP area has the most scripts in its archive. With just more than 4,000 scripts, the PHP section has almost twice as many scripts as the Perl section, which lags at a distant second with about 2,000. Once you select the PHP repository to browse, you'll see more than 60 different categories from which to choose. Most sites with script repositories have similar category lists.

Some sites have little to no quality control or submission guidelines for scripts that are added to their repositories, but Devshed's script.com has fairly rigorous rules. Submission guidelines protect you from malware and other harmful scripts or techniques that can damage your site or clobber a visitor's browser. Each script listed has a full description of the script, a rating, a link to the script author's site, and a price. Not all of the scripts are free. In fact, some are expensive, but you generally receive support, upgrades, and possibly other services (such as hosting) for the listed price. Some scripts are free for personal use but require a fee for commercial use.

phpbuilder.com

PHP Builder is 100% dedicated to the usage and development of PHP scripts. The community is active and kind to newcomers. Also, you'll find a Newbies forum where you can post the question that has been answered for the millionth time without fear of being flamed - although you should perform a search before posting. Like most community sites, you must register (it's free) and log in before posting or participating. PHP Builder is one of the most professional and well-maintained community sites I have used.

The Code Library is smaller than the others - at only a few hundred scripts - but often you can grab code snippets in the forums to solve your problems. If you aren't sure about your programming skills, there is a Coding Critique forum where you can paste in your own code for critique, correction, or enhancement. PHP Builder's strength lies not in its code library but in its community. If you need answers, this is the place to go.

weberdev.com

Weberdev - a must-have in your PHP tool kit - has forums, code, links, and tutorials that are second to none. If you need to come up to speed on an aspect of PHP programming, keep Weberdev.com in mind. The code library is a little awkward to navigate, but the search engine is fast and smart.

After you find a script you want and select it from the list, the search engine also creates related listings with associated categories based on your criteria. This smart search and retrieval process may help you find exactly what you're looking for without spending hours doing keyword or pattern searches.

phpclasses.org

To use any of the scripts at PHP Classes, you must register and log in, but you'll be glad you did. PHP Classes are object-oriented (OO) code snippets that you can add to your own code. To use the classes and scripts, you must have at least a cursory understanding of OO coding techniques. Fortunately, most of the class authors provide documentation and working examples of their code as complete PHP pages.

You can read author blogs, request more information about a class directly from an author, get involved in the forums for questions and answers, or simply grab classes from the vast repository. I have used several classes from this site that are still working after almost four years in production. Bookmark this site as an excellent resource for PHP scripts, classes, and code snippets.

The site also has a mailing list that notifies subscribers about new classes when they are added to the repository -- the emails include a summary of the class, its classification, and a short author bio. New classes are added daily.

php.net

php.net is the official PHP website, where all PHP knowledge and code originate. Although there is no code library per se, you will find a tremendous amount of code on this site.

Search for any function - fwrite, for example - and the page describing the syntax and usage for the fwrite function appears. Continue scrolling down the page to see code snippets demonstrating fwrite in action.

advancescripts.com

The sea of flashing banners and ads may be the first thing that strikes you about the AdvanceScripts site. This site has a lot to offer and is worth a browse, so don't be totally put off by their means of support. AdvanceScripts hosts almost 6,000 PHP scripts in its repository.

Like the other sites, not all of the scripts are free, so be cautious as you pick and choose.

Download, Tweak, and Use

For purposes of illustration, I decided to grab a script from one of the sites and localize it for my own use. This quick example will show you how easy it is to implement a tool from a code library. Because I work a lot with databases and PHP, I decided to find a database-related script. From the Scripts.com library, I chose PHP Scripts | Database Tools and found DaDaBIK (Databases Interface Kreator). The official description is:

"...a free PHP application that allows you to easily create a highly customizable web form interface for a MySQL database in order to search, insert, update, and delete records; all you need to do is specify a few configuration parameters.

Before downloading the script. I glanced at the description to ensure that DaDaBIK fit my situation. The script is small (1.6MB), well documented, and free (under the GPL). The minimum requirements for DaDaBIK are a PHP version >4.05 and a Database (MySQL, Oracle, PostgreSQL, or MS SQL).

Installation steps for DaDaBIK are similar to what you'll find with other Internet scripts. Download and untar the DaDaBIK package from the scripts.com site, then look for the documentation.htm file, which provides installation instructions. According to the instructions, copy the the program_files directory to the webroot directory, and rename program_files to dadabik when you copy it to webroot.

Open include/config.php and enter the parameters shown in Table 1. Once the parameters are entered and saved, open a browser and point it to DaDaBIK's install page http://www.mysite.com/dadabik/install.php (Figure 1). Click the button to install DaDaBIK. When the installation is complete, you'll see a screen similar to Figure 2, which displays warnings and installation messages.

Figure 1: Launch the installation from the DaDaBik installation screen.

Figure 2: After the installation is complete, you'll see a summary of any warnings and installation messages.

Click the link at the top of the page to exit the administration area. Next, you'll be redirected to the index.php page, where you'll see your first database table (Figure 3). The tables are listed alphabetically in the drop-down list. From this page, you may edit, insert, delete, or search records.

Figure 3: The index.php page lets you view table information.

As you can see, DaDaBIK is simple to install and quick to configure and use. This example was successful because of the excellent documentation included with the tool. When you're searching a code library, always choose scripts, classes, and applications that have thorough documentation.

Unless you are an expert programmer who can muddle through another programmer's code on your own, you'll be far better off with a well-documented product. Rarely does a script's internal documentation (comments in the code) fully explain its behavior.

Summary

Many programmers think they must produce 100 percent of the code for an application. Using code snippets and ideas from other programmers is an excellent way to improve your own programming skills; however, your work isn't done by simply downloading a script or code snippet - you must still conform the code to your own environment. Often, this is no easy task. Use the resources available and get to know other professionals along the way. Soon you'll be the one who is helping others.