【发布时间】:2017-06-09 14:03:48
【问题描述】:
我无法在 xml 文件中获取歌曲类型。首先,我正在使用
加载 XML 文件$xmlDoc = file_get_contents('/songs.xml');
一旦文件被加载到一个字符串中,我使用
将它们分解成一个数组$songs = explode("<song>", $xmlDoc);
我曾尝试使用foreach 循环遍历每首歌曲,然后分解类型,但这并没有给我它包含Rock</type> 的类型。
songs.xml
<songs>
<song>
<title>Paradise City</title>
<artist>Guns & Roses</artist>
<type>Rock</type>
</song>
<song>
<title>One Love</title>
<artist>Bob Marley</artist>
<type>Reggae</type>
</song>
<song>
<title>Sweet Child Mine</title>
<artist>Guns & Roses</artist>
<type>rock</type>
</song>
</songs>
【问题讨论】: