簡體   English   中英

使用simplexml_load_file()解析XML

[英]Parsing XML using simplexml_load_file()

如果我解析XML並使用以下內容獲取圖像simplexml_load_file(),則使用simplexml_load_file(),

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [size] => small
        )
    [0] => http://userserve-ak.last.fm/serve/34s/72903330.png
)

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [size] => medium
        )
    [0] => http://userserve-ak.last.fm/serve/64s/72903330.png
) // ... etc

我的問題是...我如何到達array [0]處的圖像URL? 我知道如何使用attributes()方法訪問“大小”屬性。 但我似乎無法回顯URL。 我試過了

$img = $xml -> album -> image[0];  <----i see nothing
$img = $xml -> album -> image -> 0;   <-----i get a 500 error

任何幫助將不勝感激。 謝謝! -鮑勃

(string) $xml->album->image;

要么

(string) $xml->album->image[0];

應該做到的。

您也可以嘗試

$xml->album->image->asXML();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM