【发布时间】:2013-01-19 18:20:39
【问题描述】:
我试图解析一个包含基本属性的简单 xml 字符串
<hash>
<engine-type>
I4 DI
</engine-type>
<body-style>
SAV 4D
</body-style>
<year>
2012
</year>
</hash>
当我尝试打印出 xdebug 给出的这 2 个属性 engine-type 和 body-style 时出现问题
$result = simplexml_load_string($query);
$enginetype = $result->engine-type;
$bodystyle = $result->body-style ;
echo $enginetype .'<br />'. $bodystyle ;
这些是来自 xdebug 的错误
Notice: Use of undefined constant type - assumed 'type'
Notice: Use of undefined constant style - assumed 'style
当我尝试将它们保存到我的数据库时,值 0
其他属性工作正常
【问题讨论】:
-
php.net/simplexml.examples-basic - 示例 #3
-
注意,这些不是 XML 意义上的属性。它们是子元素。
标签: php xml xml-parsing