graham23s Posted November 16, 2009 Share Posted November 16, 2009 Hi Guys, after afew hours i have coded an amazon api handler, i receive the response which is in xml format but i am having trouble getting the data from the returned xml. code: // Execute the function to return our URL $url = amazon_signed_request("co.uk", $parameters, $PublicKey, $PrivateKey); // Load the results and get the contents //$response = file_get_contents($execute); // Test //$xmlObject = htmlspecialchars($response); //print $xmlObject; $response = simplexml_load_file($url); /*foreach ($response->Items->Item as $item) { $Title [] = $item->ItemAttributes->Title; $img [] = $item->SmallImage->URL; } foreach($Title as $CurrentTitle) { echo "<h2>".$CurrentTitle."</h2>"; } foreach($img as $imgTitle) { echo "<img src=".$imgTitle.">"; }*/ foreach ($response->Items->Item as $item) { $title = $items->ItemAttributes->Title; $price = $items->Item->OfferSummary->LowestNewPrice->FormattedPrice; $asin = $items->Item->ASIN; $img_src = $items->Item->SmallImage->URL; $desc = strip_tags($items->Item->EditorialReviews->EditorialReview->Content); if (strlen($desc) > 300) { $desc = substr($desc,0,299); $desc = preg_replace("/\s+[,\.!?\w-]*?$/",'...',$desc); } $href = 'http://www.amazon.com/gp/product/'. $asin .'?ie=UTF8&tag=YOUR-ASSOCIATE-ID&linkCode=as2'. '&camp=1789&creative=9325&creativeASIN='. $asin; $buy = ' <a rel="nofollow" href="'. $href .'" title="'. $title .'">'. 'Buy for: '. $price .'</a>'; $html .= '<div style="clear:both;"><h3 class="title">'. $title .'</h3>'; $html .= '<div style="float:left;padding:5px 10px 5px 0;">'. '<a rel="nofollow" href="'. $href .'" title="'. $title .'"><img alt="" src="'. $img_src .'"/></a></div>'; $html .= '<div><p>'. $desc . $buy .'</p></div></div>'; } print $html; This part i have commented out works, but it's the code at the bottom i'm having trouble with, my nodes must be slightly out lol thanks for any help guys Graham Quote Link to comment Share on other sites More sharing options...
graham23s Posted November 16, 2009 Author Share Posted November 16, 2009 Fixed! sorry guys $items should have been $item in the foreach. Graham Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.