Page 508 - Beginning PHP 5.3
P. 508
Part III: Using PHP in Practice
Summary
In this chapter you explored PEAR, the PHP Extension and Application Repository: a vast collection of
free, reusable code that you can incorporate into your own PHP projects. By using PEAR packages,
you ’ re building your Web applications on a base of prewritten, peer - reviewed, thoroughly tested code,
saving you a large amount of time with both coding and bug hunting.
As you worked through this chapter, you:
❑ Studied the PEAR package manager
❑ Learned how to install and remove PEAR packages, as well as how to work with dependencies
❑ Wrote a script to detect a visitor ’ s browser and operating system using the PEAR Net_
UserAgent_Detect package
❑ Used the HTML_Table package to generate a table of Fibonacci numbers
❑ Learned how to use the powerful HTML_QuickForm package to generate, handle, and validate
Web forms
❑ Rewrote the registration script from the previous chapter to use HTML_QuickForm , resulting in a
cleaner, shorter script that ’ s easier to maintain
This chapter has given you a taste of the power and usefulness of PEAR. Try working through the
following exercises so that you get used to writing PEAR - based applications, and don ’ t forget to check
out the repository of packages at http://pear.php.net/packages.php for other ideas. You can find
the solutions to these exercises in Appendix A.
In the next chapter you explore ways to deal with the outside world from your PHP scripts, including
talking to the Web server, sending email, and handling dates and times.
Exercises
1. Download and install the Numbers_Roman PEAR package, and use it to write a script that
displays the integers 1 to 100 as Roman numbers.
2. Use Numbers_Roman and HTML_QuickForm to write a Roman - to - Arabic number converter.
The user can enter a number in either Roman or Arabic format and then click a Convert
button. The script then displays the number in the alternate format.
470
9/21/09 9:14:57 AM
c15.indd 470
c15.indd 470 9/21/09 9:14:57 AM