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
https://forums.phpfreaks.com/topic/181798-xml-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.