INCUTIO HOME | SCRIPTS | CONTACT

PHP Amazon Search

Click here to view the demo | Click here for Simon Willison's Weblog

PHP Amazon Search is an example implementation of Amazon's new web service API in PHP. It is intended as a starting point for PHP developers who want to experiment with this exciting new technology, without having to solve the initial problems of URL construction, page retrieval and XML parsing themselves.

Notes on Implementation

This demonstration uses the URL based interface to Amazon rather than the SOAP one, simply because the URL based one is less complicated to implement. A URL is constructed which contains a developer key, associate ID and search term and this is then used to retrieve search results from Amazon in XML. The XML is then parsed to create an array of AmazonProduct objects, which can by be cycled through and processed to display a results page.

XML retrieval is achieved using the Snoopy web client class. Retrieval through PHP's built in file() and fopen() functions is not currently possible, possibly due to extra headers sent by Amazon's server (see the comments on fopen in the PHP manual for more details). Snoopy can be downloaded from Sourceforge.

The sample script amazonsearch.php only makes use of the searchTerm() and searchRelated() methods of the AmazonSearchEngine class - searchAuthor() and searchISBN() are also available.

Requirements

To run PHP Amazon Search you will need:

Download PHP Amazon Search

You can either grab an archive containing all three files, or grab the files seperately here:

Alternatives

Feedback or Suggestions?

Email simon AT incutio DOT com. Keep an eye on my weblog for related news and updates.

scripts.incutio.com light logo