如何从 php 中的 MusicBrainz simplexml_load_file() 获取值?

问题描述

我知道到目前为止有一些与 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 结果中获得任何值

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)