1

I'm trying to get data from a 3rd party feed using their API. The format it comes over in is XML allegedly, but bears little resemblance to it with my untrained eye. Here's what it looks like echoed to the screen with php:

122701 29 Epound_10_-_Epound_20 13 Epound_20_-_Epound_30 1 Epound_30_-_Epound_40 4 Epound_40_-_Epound_50 11 532601 13 4896423 10 283701 6 0 29 0__-_100_ 29 BRAND NEW BOXED 8GB 4TH GEN STYLE MP4 PLAYER MUSIC VIDEO WITH IPOD CONNECTION LIMITED STOCK AT THIS PRICE! PINK RED BLUE SILVER PURPLE BLACK GREEN FEATURES USB 2.0 version with capacity: 8GB Holds Up to 1600 Songs 2 inch TFT Screen, 260K true colors display Support multiple music formats: MP1, MP2, MP3,WMA, http://r.3rdparty.com/r/uk/532601/122701/90/90/http%3A%2F%2Fi.ebayimg.com%2F00%2Fs%2FMzg1WDU5OQ%3D%3D%2F%24%28KGrHqN%2C%21lME6CWISze5BOsD3p%28T0%21%7E%7E60_1.JPG%3Fset_id%3D8800005007/voAX7N1WHJJIu1oTgPhOqVsRjHMhQEX45KQtKDk2t4o- 90 90 http://r.3rdparty.com/r/uk/532601/122701/auto/auto/http%3A%2F%2Fi.ebayimg.com%2F00%2Fs%2FMzg1WDU5OQ%3D%3D%2F%24%28KGrHqN%2C%21lME6CWISze5BOsD3p%28T0%21%7E%7E60_1.JPG%3Fset_id%3D8800005007/voAX7N1WHJJIu1oTgPhOqVsRjHMhQEX45KQtKDk2t4o- http://ecs-uk.3rdparty.com/ctl/go/sitesearchGo?.ts=1352310761409&.sig=v6kMZQynUtJjAqTcYY01ZY_OGEM-&offerId=81b44a3770af829494b013d20aaf433a&searchId=1076987819567_1352310761409_2488241&affiliationId=12345678&country=uk&wait=true&ecs=ok&contextLevel=1&merchantid=532601&comId=532601&catId=122701 http://3rdparty.com/p-mp3-players-122701/bush-mp3-8gb-19657960?partnerId=12345678 eBay.co.uk http://3rdparty.com/data/merchantlogos/532601/ebay-logo-640.jpg 80 24 122701-19657960 Bush MP3 8GB MP3 Players 11.49 2.99 2.99 14.48 0 1 false Sound & Vision:iPods & MP3 Players| iPods & MP3 Players Bush 567 Features: * Connections: 1 x 30 Pin Ipod connection port, 1 x 3.5mm jack headphone output * Playable formats: MP3, AMV, WMV, ASF Video, JPG, TXT, LRC, WAV * Suitable for use with Windows PCs and MAC * Integrated long lasting lithium-ion battery * Built-in equalizer with 7 presets * Built-in Clock * Integrated http://r.3rdparty.com/r/uk/4896423/122701/90/90/http%3A%2F%2Fecx.images-amazon.com%2Fimages%2FI%2F31IHNu5OI5L._SL160_.jpg/Nw1b8PcAtWqiL74fE7oiiBurTgUSoIiWBYGvjkSH8hc- 90 90 http://r.3rdparty.com/r/uk/4896423/122701/auto/auto/http%3A%2F%2Fecx.images-amazon.com%2Fimages%2FI%2F31IHNu5OI5L._SL160_.jpg/Nw1b8PcAtWqiL74fE7oiiBurTgUSoIiWBYGvjkSH8hc- http://ecs-uk.3rdparty.com/ctl/go/sitesearchGo?.ts=1352310761409&.sig=Zh1tMTvh5S8dhWh3uC7CZYgI7rc-&offerId=661a194e6394057cf5315e16c23802b3&searchId=1076987819567_1352310761409_2488241&affiliationId=12345678&country=uk&wait=true&ecs=ok&contextLevel=1&merchantid=4896423&comId=4896423&catId=122701 http://3rdparty.com/p-mp3-players-122701/atlantic-agsil8-8gb-19803999?partnerId=12345678 Amazon Marketplace http://3rdparty.com/data/merchantlogos/4896423/Amazon_marketplace.gif 80 24 122701-19803999 Atlantic AGSIL8 8GB MP3 Players 11.99 3.99 3.99 15.98 0 1 Usually dispatched within 1-2 business days false 0608938410283 Electronics & Photo/Categories/Portable Sound & Vision/MP3 & Digital Media Players Atlantic 11695 brand new 8gb mp4 player very similar to the ipod nano,ipod chargers also work on this 2) Support multi-lanuages:English,French,German, Itlian,Spainish,ect 26 lanuages. 3) Play Mp3 4) Play movies 5) ID3 Lyrics display 6)  

My question is, how do I convert this using php and extract the data? There seem to be no fieldnames like there are in the XML data examples I have seen, eg "Title", "Image" etc.

I have read this Stack Overflow question, but it doesn't help me with this feed:

How to use XMLReader in PHP?

Thanks in advance.

Community
  • 1
  • 1
Sara44
  • 422
  • 1
  • 9
  • 25
  • 1
    It doesn't look like XML even remotely; more like a table of a kind. What happens if you `var_dump` this data instead? – raina77ow Nov 12 '12 at 14:28
  • 2
    View the page source instead of displaying the document. Browsers treat unrecognized elements as `div`s and display just the text nodes within them by default. You're probably just echoing these into an HTML page, hence the confusion. – toniedzwiedz Nov 12 '12 at 14:44
  • That's got it Tom, thanks for your speedy reply guys, much appreciated! – Sara44 Nov 12 '12 at 15:10

1 Answers1

0

if you wan't to read xml data please follow those steps,

$xmlURL = "your xml url goes here";

try {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $xmlURL);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-type: text/xml'
    ));
    $content = curl_exec($ch);
    $error   = curl_error($ch);
    curl_close($ch);
    $obj = new SimpleXMLElement($content);
    echo "<pre>";
    var_dump($obj);
    echo "</pre>"; 
}
catch(Exception $e){
    var_dump($e);exit;
}

You will get array formate of whole xml file.

Thanks.

Dilip Borad
  • 179
  • 5
  • 19