解析错误:语法错误,意外的 T_OBJECT_OPERATOR
尝试将 myXml.xml 中的一些数据添加到字符串时,出现以下错误:解析错误:语法错误,意外的 T_OBJECT_OPERATOR。
$xmlstr = file_get_contents('myXml.xml');
$xml = new SimpleXMLElement($xmlstr);
foreach($xml->order as $order){
$replace = array();
$firstName = (string) $order->billing-address->first-name;
$lastName = (string) $order->billing-address->last-name;
}
我无法直接提供 XML,因为它包含敏感数据。
谢谢, 山姆
I'm getting the following error when trying to add some data from myXml.xml to a string: Parse error: syntax error, unexpected T_OBJECT_OPERATOR.
$xmlstr = file_get_contents('myXml.xml');
$xml = new SimpleXMLElement($xmlstr);
foreach($xml->order as $order){
$replace = array();
$firstName = (string) $order->billing-address->first-name;
$lastName = (string) $order->billing-address->last-name;
}
I can't provide my XML directly as it contains sensitive data.
Thanks,
Sam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
-
符号表示减法。要在属性名称中使用它,必须使用以下语法:一般来说,最好使用
firstName
、billingAddress
等作为属性名称来避免这种情况。请参阅CamelCase。然而,在这种情况下,您可能无法控制 XML 输入。The
-
sign means subtraction. To use it in property names, you must use this syntax:In general, it's probably better to use
firstName
,billingAddress
, etc. as property names to avoid this. See CamelCase. In this case, however, you may have no control over the the XML input.