我知道到目前为止有一些与 MusicBrainz 相关的主题对我有帮助,但我被困在下面。
我无法从结果中回显值
<?php
ini_set('user_agent', 'MyApp/1.0 (music@test.com)') ;
$xml = simplexml_load_file('http://musicbrainz.org/ws/2/artist/?query=artist:eminem');
print_r($xml);
?>
PHP 结果示例
SimpleXMLElement Object
(
[@attributes] => Array
(
[created] => 2021-01-08T14:46:14.802Z
)
[artist-list] => SimpleXMLElement Object
(
[@attributes] => Array
(
[count] => 1
[offset] => 0
)
[artist] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => b95ce3ff-3d05-4e87-9e01-c97b66af13d4
[type] => Person
[type-id] => b6e035f4-3ce9-331c-97df-83397230b0df
)
[name] => Eminem
[sort-name] => Eminem
[gender] => male
[country] => US
[area] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 489ce91b-6658-3307-9877-795b68554c98
[type] => Country
[type-id] => 06dd0ae4-8c74-30bb-b43d-95dcedf961de
)
[name] => United States
[sort-name] => United States
[life-span] => SimpleXMLElement Object
(
[ended] => false
)
)
现在,当我按照下面的方式回显艺术家姓名时,我没有得到任何输出
<?php
ini_set('user_agent', 'MyApp/1.0 (music@test.com)') ;
$xml = simplexml_load_file('http://musicbrainz.org/ws/2/artist/?query=artist:eminem');
//print_r($xml);
echo $xml->artist->name;
?>
请你解释一下我做错了什么我似乎无法从 xml 结果中获取任何值