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 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持