Five Minutes :: $pear->list

I've seen three people ask a variation of how can I get a list of installed PEAR packages from within my PHP script in the last few weeks on IRC, and two just in the last day. Because I'm a helpful sort, here's a little morsel of code that will do just that:

[sourcecode language="php"] include 'PEAR/Registry.php'; $reg = new PEAR_Registry; foreach ($reg->listPackages() as $package) { print "$package\n"; } [/sourcecode]

This should work with pretty much any version of PEAR.

(Update: Ken has a nifty bit of code in the comments to check for a specific installed version of a package.)

Back to index

Copyright © 2006-10 Adam Harvey. Original content is licensed under a Creative Commons Attribution 2.5 Licence.