2012-11-12 26 views
1

我試圖從使用其API的第三方訂閱源獲取數據。據說它的格式是XML,但與我未經訓練的眼睛幾乎沒有相似之處。這裏是什麼樣子顯示在屏幕上用php:如何從訂閱源導入XML數據

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) 

我的問題是,我該如何轉換這種使用PHP和提取數據?似乎沒有像我看到的XML數據示例中的字段名稱,例如「標題」,「圖像」等。

我已閱讀此堆棧溢出問題,但它不幫助我使用此源:

How to use XMLReader in PHP?

在此先感謝。

+1

即使遠程它看起來也不像XML;更像是一種表格。如果你'var_dump'這個數據會發生什麼呢? – raina77ow

+2

查看頁面源代替顯示文檔。瀏覽器將無法識別的元素視爲'div',並默認顯示其中的文本節點。你可能只是將它們反映到一個HTML頁面中,因此造成混亂。 – toniedzwiedz

+0

這就是它湯姆,感謝您的快速回復傢伙,非常感謝! – Sara44

回答

0
如果你wan't讀取XML數據請遵循這些步驟

$ XMLURL = 「你的XML鏈接到這裏」;

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; 
} 

您將獲得整個xml文件的陣列合成器。

謝謝。