Amazon Web Services Product Search
This example displays products available from Amazon via the Amazon Web Services API, using the REST request method. Click here to view the live output from this script.
<?php
require("MagicParser.php");
if (!$_GET["q"]) $_GET["q"] = "DVD Player";
print "<h1>Amazon Web Services Product Search (Electronics)</h1>";
print "<form method='GET'>";
print "<input type='text' name='q' value='".htmlentities($_GET["q"])."' /> ";
print "<input type='submit' value='Search' />";
print "</form>";
function myRecordHandler($item)
{
print "<h3><a href='".$item["DETAILPAGEURL"]."'>".$item["ITEMATTRIBUTES/TITLE"]."</a></h3>";
print "<img src='".$item["SMALLIMAGE/URL"]."' />";
print "<br /><br />";
}
if ($_GET["q"])
{
// construct Amazon Web Services REST Query URL
$url = "http://webservices.amazon.co.uk/onca/xml?Service=AWSECommerceService";
$url .= "&Version=2005-03-23";
$url .= "&Operation=ItemSearch";
$url .= "&ContentType=text%2Fxml";
$url .= "&SubscriptionId=0VSBK4FNHZ2K95R3N2G2";
$url .= "&ResponseGroup=Images,Medium";
$url .= "&SearchIndex=Electronics";
$url .= "&Keywords=".urlencode($_GET["q"]);
// fetch the response and parse the resultsz
MagicParser_parse($url,"myRecordHandler","xml|ITEMSEARCHRESPONSE/ITEMS/ITEM/");
}
?>