Hey I have two things I need to sort out, simplexml and checking if a file exists. Firstly, simpleXML. I know how to parse all the data but I always get confused on how to access it... This is the feed I'm pulling data from, I want to access <item> but I'm not sure what path thing I do, e.g $amazonKey = "1QXMAKM6KD613QF2XT02"; $buyAmazon = simplexml_load_file("http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&SubscriptionId=" . $amazonKey . "&Operation=ItemSearch&Keywords=" . $track->title . "&SearchIndex=Music&ResponseGroup=Medium&Version=2008-04-07"); echo $buyAmazon->[B]ItemSearchResponse->Items->Item[0]->[/B]DetailPageUrl; Code (markup): That shows nothing so I assume the bit I bolded is wrong, and I dont know what else to put.. Secondly, whats the best way to check if a remote file is a valid MP3 file?
Thanks for the help - I've done that and got SimpleXMLElement Object ( [OperationRequest] => SimpleXMLElement Object ( [HTTPHeaders] => SimpleXMLElement Object ( [Header] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => UserAgent ) ) ) [RequestId] => 1WSA8ZPKPVK8Z8J0AQNQ [Arguments] => SimpleXMLElement Object ( [Argument] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => SearchIndex [Value] => Music ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Service [Value] => AWSECommerceService ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Keywords [Value] => Lollipop (Remix) feat. Gorilla Zoe ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => SubscriptionId [Value] => 1QXMAKM6KD613QF2XT02 ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => ResponseGroup [Value] => Medium ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Operation [Value] => ItemSearch ) ) [6] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Version [Value] => 2008-04-07 ) ) ) ) [RequestProcessingTime] => 0.0317389965057373 ) [Items] => SimpleXMLElement Object ( [Request] => SimpleXMLElement Object ( [IsValid] => True [ItemSearchRequest] => SimpleXMLElement Object ( [Keywords] => Lollipop (Remix) feat. Gorilla Zoe [ResponseGroup] => Medium [SearchIndex] => Music ) [Errors] => SimpleXMLElement Object ( [Error] => SimpleXMLElement Object ( [Code] => AWS.ECommerceService.NoExactMatches [Message] => We did not find any matches for your request. ) ) ) [TotalResults] => 0 [TotalPages] => 0 ) ) [/code] PHP: Which doesnt do that much apart from confuse me.
If you want to print every item, use this code: $amazonKey = "1QXMAKM6KD613QF2XT02"; //your key $buyAmazon = simplexml_load_file("http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&SubscriptionId=" . $amazonKey . "&Operation=ItemSearch&Keywords=" . $track->title . "&SearchIndex=Music&ResponseGroup=Medium&Version=2008-04-07"); //the file for ( $i=1; $i < $buyAmazon->ItemSearchResponse->TotalResults; $i++ ) { //starts a counter foreach ($buyAmazon->ItemSearchResponse->Items as $item) { //for every item echo 'URL: <a href="'.$item.'">Result #'.$i.'</a>'; //echo the url } } PHP:
Thanks, but I'm still confused, for example, I have the following in my code: if(!empty($getSuggestions->resultList->result[0]->artist)) { echo '<p>Perhaps you were looking for a song by one of the following artists?</p>'; Code (markup): Since I only ever have one result, I just want to see if the record is actually there, so I need to check if DetailPageURL is empty or not, like the code I just posted.
$amazonKey = "1QXMAKM6KD613QF2XT02"; //your key $buyAmazon = simplexml_load_file("http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&SubscriptionId=" . $amazonKey . "&Operation=ItemSearch&Keywords=" . $track->title . "&SearchIndex=Music&ResponseGroup=Medium&Version=2008-04-07"); //the file $detail = $buyAmazon->ItemSearchResponse->Items->DetailPageURL; //<!-- the url -- note: it's just the first item if ( empty($detail) ) { //UH-OH!!! It's empty!! } else { //It's not empty } PHP: