带有破折号 ( - ) 的 php simplexml_load_file [英] php simplexml_load_file with a dash ( - )

查看:36
本文介绍了带有破折号 ( - ) 的 php simplexml_load_file的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力从 php 中的 xml 文件中获取数据...

Hi I'm struggling to get data from an xml file in php...

xml 文件在这里:http://musicbrainz.org/ws/2/artist/8bfac288-ccc5-448d-9573-c33ea2aa5c30?inc=release-groups

到目前为止,在将它作为 $xml 加载到 simplexml_load_file 中之后我想做这样的事情:

and so far after loading it into simplexml_load_file as $xml I want to do something like this:

<?php
$url = "http://musicbrainz.org/ws/2/artist/8bfac288-ccc5-448d-9573-c33ea2aa5c30?inc=release-groups";
$xml = simplexml_load_file($url);

$releasegrouplist = "release-group-list"; 
$releasegroup = "release-group";

$i = "0";
for ($i = 0; $i <= 30; $i++)
  {
   echo "release: " . $xml->artist->$releasegrouplist->$releasegroup[$i]->title;}

当我尝试在带有 $i 变量的 for 循环中使用它时出现问题,如上所示.

The problem arises when I try to use it in a for loop with an $i variable as shown above.

有什么提示或更简单的方法来做到这一点吗?

Any tips or easier ways to do this?

谢谢大家

推荐答案

试试这个语法.此脚本适用于我的以下更改(PHP 5.3.6).

Try this syntax instead. This script works for me with the change below (PHP 5.3.6).

echo "release: " . $xml->artist->{'release-group-list'}->{'release-group'}[$i]->title;

来源

这篇关于带有破折号 ( - ) 的 php simplexml_load_file的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆