2017-10-08 111 views
1

我試圖從他們的XML中獲取PS4固件版本,但由於某種原因它返回NULLSimpleXML從XML獲取固件版本

<?php 
    $list = simplexml_load_file('http://feu01.ps4.update.playstation.net/update/ps4/list/eu/ps4-updatelist.xml'); 

    if($list) { 
     echo $list->system_pup[0]['label']; // get firmware version 
    } else { 
     echo 'Error opening the XML file.'; 
    } 
?> 

我不知道我做錯了什麼,因爲我已經按照this article,似乎我已經正確地做到了。

任何想法?

回答

3

如果訪問了錯誤的元素的SimpleXML不會拋出它只是給你,你調用返回的虛無錯誤。您應該查看結構以確定元素在結構中的位置。在這種情況下,你關閉了1個元素。

$list = simplexml_load_file('http://feu01.ps4.update.playstation.net/update/ps4/list/eu/ps4-updatelist.xml'); 
if($list) { 
    //print_r($list); 
    echo $list->region->system_pup[0]['label']; // get firmware version 
} else { 
    echo 'Error opening the XML file.'; 
} 
1

另一種選擇可以訪問屬性的節點的attributes()功能:

$list = simplexml_load_file('http://feu01.ps4.update.playstation.net/update/ps4/list/eu/ps4-updatelist.xml'); 

echo $list->region->system_pup->attributes()->label;