2.4. Using a PEAR Package in Your Own Code

After you install the packages you need (you can read about that process in the preceding sections), you can use those packages by simply including a reference to a package in your source code, then using the functions included in that package. For example, say you installed the Date package. You can use the Date class and its member functions as if it were part of PHP:

<?php
     include_once("Date.php");
     $today = new Date('2007-09-25T16:24:52');
     Echo $today->getDate();
?>

Be sure to read the documentation for any package that you install so you know what's available to you. Chances are, unless you want to do something incredibly unique, you can find a built-in function to accomplish the task.

Get PHP & MySQL® Web Development All-in-One Desk Reference for Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.