Guest User

Untitled

a guest
Jul 12th, 2018
3,311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.26 KB | None | 0 0
  1. <HTML>
  2. <head>
  3. <title>Amazon search test</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <style type="text/css">
  6. UNKNOWN {
  7.     FONT-SIZE: small; COLOR: #000000; FONT-FAMILY: verdana, sans-serif
  8. }
  9. BODY {
  10.     FONT-SIZE: small; FONT-FAMILY: verdana, sans-serif
  11. }
  12. pre {background:#eeeeee;border:1px solid #777777;padding:4px}
  13.  
  14. </style>
  15. </head>
  16. <BODY BGCOLOR=#FFFFFF >
  17.  
  18. <!-- search form -->
  19. <form name="htmlform" method="post" action="test.php">
  20. title search: <input type="text" name="title" maxlength="50" size="30">
  21. <input type="submit" value="Submit">  
  22. </form>
  23.  
  24. <!-- query Amazon and show result -->
  25. <?php
  26.     // associations between a label and its organization
  27.     $labels = array(
  28.         'MGM' => 'RIAA',
  29.         'Universal Music' => 'GEMA'
  30.     );
  31.    
  32.     // test, if there was a search word submitted
  33.     if(isset($_POST['title'])) {
  34.         // query Amazon
  35.     include("amazon_api_class.php");
  36.     $obj = new AmazonProductAPI();
  37.     try {
  38.         $result = $obj->searchProducts($_POST['title'], AmazonProductAPI::DVD, "TITLE");
  39.     } catch(Exception $e) {
  40.         echo $e->getMessage();
  41.     }
  42.    
  43.     /*
  44.     // debug ouput of the result XML
  45.     echo "<pre>"
  46.     print_r($result);
  47.     echo "</pre>"
  48.     echo "<hr>"
  49.     */
  50.  
  51.         // show result
  52.         echo "<hr>";
  53.         foreach ($result->Items->Item as $item) {
  54.         echo "Title : {$item->ItemAttributes->Title}<br>";
  55.         echo "ASIN : {$item->ASIN}<br>";
  56.         $label = $item->ItemAttributes->Label;
  57.         echo "Label : {$label}<br>";
  58.        
  59.         // search for the label: test all entries in the labels array,
  60.         // if the label is part of the returned label, ignore lower/uppercase
  61.         $org = "unknown";
  62.             foreach ($labels as $labelTest => $organization) {
  63.                 if (strpos(strtolower($label), strtolower($labelTest)) !== false) {
  64.                     $org = $organization;
  65.                     break;
  66.                 }
  67.             }
  68.            
  69.             // show result
  70.         echo "Organization: $org<br>";
  71.        
  72.         // show image
  73.         echo "<img src=\"" . $item->MediumImage->URL . "\" /><br>";
  74.         echo "<hr>";
  75.         }    
  76.     }
  77. ?>
  78.  
  79. <HR>
  80. <p><a href="mailto:fb@frank-buss.de"><img src="../img/email.gif" width="64" height="64" align="left" border="0"></a>
  81. <address>
  82. 22. M&auml;rz 2012, <a href="mailto:fb@frank-buss.de">Frank Bu&szlig;</a>
  83. </address>
  84. </body>
  85. </html>
Add Comment
Please, Sign In to add comment