Getting started with PEAR
PEAR is short for “PHP Extension and Application Repository” and provides a library for PHP code.
Installation
When using PHP >= 4.3.0, the PEAR Package Manager is already installed unless one has used the ./configure option –without-pear.
Windows
After you have downloaded and installed PHP, you have to manually execute the batch file located in e.g. c:\php\go-pear.bat. The setup will ask you some questions and afterwards the PEAR Package Manager will be installed in the path, which you have specified during installation. Finally you have to add that installation path to your PATH environment. Either do this manually (Start > Control Panel > System > Environment) or run (double-click) the newly generated PEAR_ENV.reg that’s now found in the PHP source directory. After that you can access the PEAR Package Manager by running the command pear in a Windows Command Prompt.
To update your PEAR installation from go-pear.org, request http://pear.php.net/go-pear in your browser and save the output to a local file go-pear.php. You can then run
PEAR in hosting environments
If you are running your site at a web hosting provider with no direct access to the server (via local logins, Telnet or SSH), you can use the PEAR Installer using the Web Frontend.
- Go to http://pear.php.net/go-pear and save as go-pear.php
- Put go-pear.php on your webserver, where you would put your website
- Open http://yourdomain.example.org/go-pear.php in your browser
- Follow the instructions in the interface
Example: Installing and using Calendar
Calendar provides an API for building Calendar data structures. Using the simple iterator and it’s “query” API, a user interface can easily be built on top of the calendar data structure, at the same time easily connecting it to some kind of underlying data store, where “event” information is being held.
Step 1: Get Package
downloading Calendar-0.5.3.tgz …
Starting to download Calendar-0.5.3.tgz (63,274 bytes)
…………….done: 63,274 bytes
downloading Date-1.4.7.tgz …
Starting to download Date-1.4.7.tgz (55,754 bytes)
…done: 55,754 bytes
install ok: channel://pear.php.net/Calendar-0.5.3
install ok: channel://pear.php.net/Date-1.4.7
Step 2: Check installed packages
INSTALLED PACKAGES, CHANNEL PEAR.PHP.NET:
=========================================
PACKAGE VERSION STATE
Archive_Tar 1.3.2 stable
Calendar 0.5.3 beta
Console_Getopt 1.2.3 stable
Date 1.4.7 stable
MDB2 2.4.1 stable
PEAR 1.7.1 stable
PHP_CodeSniffer 1.1.0 stable
Structures_Graph 1.0.2 stable
Step 3: Writing some test code
<?php
require_once 'Calendar/Month/Weekdays.php';
$Month = new Calendar_Month_Weekdays(date('Y'), date('n'));
$Month->build();
echo "<table>\n";
while ($Day = $Month->fetch()) {
if ($Day->isFirst()) {
echo "<tr>\n";
}
if ($Day->isEmpty()) {
echo "<td> </td>\n";
} else {
echo '<td>'.$Day->thisDay()."</td>\n";
}
if ($Day->isLast()) {
echo "</tr>\n";
}
}
echo "</table>\n";
?>
Resources
Categories
- California (3)
- Cars (1)
- Cologne (3)
- Cycling (7)
- Design (1)
- Events (10)
- Gadgets (1)
- Hockey (1)
- Job (12)
- Life in General (19)
- London (7)
- Mobile (8)
- Music (3)
- Guitar (3)
- NYC (11)
- Programming (6)
- Radio (1)
- Shopping (1)
- Travel (21)
- Uncategorized (1)
- Video (1)
- Web (56)
- Coding (37)
- Agent YUI (6)
- Performance (5)
- Design (2)
- Coding (37)
Blogroll
- Neil Crosby
- Simon Jobling
- Cathy Ma
- Frederique Dame
- Aaron Gustafson
- Brad Touesnard
- Tara Hunt
- Jimmy Byrum
- Andy Clarke
- Molly Holzschlag
Recent Posts
- Boost the performance of your mobile web app using YUI Compressor
- Cycling through Death Valley, powered by REI
- Bike ride up (and down) a volcano
- Text to speech functionality in web applications using the iSpeech API
- Search along a route with CloudMade’s Local Search API