dsxsou8465 2015-07-31 09:40
浏览 197
已采纳

从simplexmlelement对象获取值

I'm having trouble with converting my simplexmlelement object to variables. This is my xml output:

<affiliate_signup_response>
  <success>false</success>
  <message>Duplicate Affiliate Contact</message>
  <affiliate_id>0</affiliate_id>
</affiliate_signup_response>

Now i've searched the net and found out that I have to do something like this to get the output:

(string) $xml[0]->succes;
(string) $xml->succes;
(string) $xml->affiliate_signup_response->succes;

I just can't seem to get the right response and am probaly missing the right clue into making this work. I really hope this is not a dumb question.

If create a foreach loop with $key and $value this is the output:

key: success value: false
key: message value: Duplicate Affiliate Contact
key: affiliate_id value: 0
  • 写回答

1条回答 默认 最新

  • donglu3243 2015-07-31 09:53
    关注

    Try

    $str = <<<XML
    <affiliate_signup_response>
      <success>false</success>
      <message>Duplicate Affiliate Contact</message>
      <affiliate_id>0</affiliate_id>
    </affiliate_signup_response>
    XML;
    
    
    $xml = new SimpleXMLElement($str);
    //var_dump($xml);
    $success = $xml->success;
    $message = $xml->message;
    $affiliate_id = $xml->affiliate_id;
    
    echo $success."<br />";
    echo $message."<br />";
    echo $affiliate_id."<br />";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

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