Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的 xml 文件中有这样的字段:
<state-code>GA</state-code>
现在我在 php 中从中获取数据。simplexml_load_file 将整个内容作为对象返回。现在还没有问题,但是当我这样写的时候
$single_property->location->state-code
它没有获取价值。但如果是或则没有问题。但我无法控制 xml 文件结构。必须找到另一种方法。怎么办?请建议。
假设所有其他未显示的代码都是正确的,您可以访问带有非法字符(-)的属性,例如:
$single_property->location->{'state-code'}