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.
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
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
searchRelated() methods of the
AmazonSearchEngine class -
searchISBN() are also available.
To run PHP Amazon Search you will need:
You can either grab an archive containing all three files, or grab the files seperately here:
Email simon AT incutio DOT com. Keep an eye on my weblog for related news and updates.