0

在我的 xml 文件中有这样的字段:

<state-code>GA</state-code>

现在我在 php 中从中获取数据。simplexml_load_file 将整个内容作为对象返回。现在还没有问题,但是当我这样写的时候

$single_property->location->state-code

它没有获取价值。但如果是或则没有问题。但我无法控制 xml 文件结构。必须找到另一种方法。怎么办?请建议。

4

1 回答 1

1

假设所有其他未显示的代码都是正确的,您可以访问带有非法字符(-)的属性,例如:

$single_property->location->{'state-code'}
于 2013-10-08T14:53:18.340 回答