好吧,所以我对此有点困惑。我有一个看起来像这样的 xml:
<track>
<artist mbid="77cceea7-91bb-4a4c-ae41-bc9c46c1ccb5"> Red Hot Chili Peppers </artist>
<name> under the bridge </name>
<streamable>0</streamable>
<mbid/>
<album mbid="0fe94139-df63-4e51-b2e7-a1d53535cdd9"> Blood Sugar Sex Magik </album>
<url> http://xxxxxx.com </url>
<date uts="1351691244">31 Oct 2012, 13:47</date>
</track>
我使用 simpleXML 来解析 xml,如下所示:
$artists = array();
$xml = simplexml_load_file("http://xxxxxxxxxxxxxx");
foreach($xml->recenttracks->track as $track)
{
$artist = $track->artist;
array_push($artists, $artist);
}
var_dump($artists);
现在我希望得到一个看起来像这样的漂亮数组:
array(4) {
[0]=>
string(20) "Red Hot Chili Peppers "
[1]=>
string(20) "Red Hot Chili Peppers"
}
但我得到的是这样的:
array(2)
{
[0]=> object(SimpleXMLElement)#6 (2) { ["@attributes"]=> array(1) { ["mbid"]=> string(36) "8bfac288-ccc5-448d-9573-c33ea2aa5c30" } [0]=> string(21) "Red Hot Chili Peppers" }
[1]=> object(SimpleXMLElement)#4 (2) { ["@attributes"]=> array(1) { ["mbid"]=> string(36) "8bfac288-ccc5-448d-9573-c33ea2aa5c30" } [0]=> string(21) "Red Hot Chili Peppers" }
}
现在我如何只获得艺术家,而不是整个 SimpleXMLElement,因为我无法弄清楚。