我有这个XML文件:
我想打印内容xml标签
我试过了:
<?php
$xml = 'http://api.radionomy.com/currentsong.cfm?radiouid=80b5e81c-c769-478a-aee7-fbe149aacfe3&apikey=cf415862-c0ac-4085-bc03-be80a26f9063&callmeback=yes&type=xml&cover=yes&previous=yes.xml';
$xmlcont = new SimpleXMLElement($xml);
echo $xmlcont->track->title;
?>
但它不起作用!!
答案 0 :(得分:0)
使用以下内容:
$xmlObj = new SimpleXMLElement('http://api.radionomy.com/currentsong.cfm?radiouid=80b5e81c-c769-478a-aee7-fbe149aacfe3&apikey=cf415862-c0ac-4085-bc03-be80a26f9063&callmeback=yes&type=xml&cover=yes&previous=yes.xml', NULL, TRUE);
$tracks = $xmlObj->xpath("//tracks");
if(count($tracks) > 0) {
foreach($tracks as $track) {
echo $track->track->title . "\n";
}
}
当您需要从网址获取数据时,只需将SimpleXMLElement
的第3个参数设置为true