douzuanze0486 2017-04-13 08:49
浏览 162
已采纳

无法从PHP中的SimpleXMLElement中提取字符串

I am trying to extract the string value from the SimpleXMLElement below (which has been returned from a SOAP endpoint) but I'm having no joy:

object(SimpleXMLElement)[476]
  public 'return' => string 'ff7ecc8af5ecaaba412c3b453c5f65f1' (length=32)

I have tried casting the entire object as a string, it just returns empty, I've tried treating 'return' as key, etc. This is such a simple task, can't believe it's got me stumped.

  • 写回答

2条回答 默认 最新

  • dporu02280 2017-04-13 09:52
    关注

    Your problem, somewhat hidden in the question, is that the element name is a reserved word, so you can't use the ordinary syntax:

    $value = (string)$xml->return; # SYNTAX ERROR
    

    The solution is to use braces and quotes around the name, which allows you to use reserved words or characters:

    $value = (string)$xml->{'return'};
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,
  • ¥15 spaceclaim模型变灰色
  • ¥15 求一份华为esight平台V300R009C00SPC200这个型号的api接口文档
  • ¥15 就很莫名其妙,本来正常的Excel,突然变成了这种一格一页
  • ¥15 字符串比较代码的漏洞
  • ¥15 欧拉系统opt目录空间使用100%
  • ¥15 ul做导航栏格式不对怎么改?