Jump to content

xml problem


graham23s

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.