dongyi6845 2013-06-11 19:16
浏览 146
已采纳

将cURL响应转换为变量

I am a noob at curl and xml, but I have searched this site and the web for an answer to this, and nothing I have found works.

I am sending XML using cURL and the recipient service is getting the data correctly and creating a response which I am receiving. The response is echo'd from curl_exec as

<TRANS>
    <HPAY>
        <ID>223</ID>
        <MLABEL>XXXX XXXX XXXX 9854</MLABEL>
        <DATE>11/06/2013 21:00:36</DATE>
        <SEN></SEN>
        <REC>sc</REC>
        <DEB>0.00</DEB>
        <CRED>10.34</CRED>
        <COM>2.00</COM>
        <MSG></MSG>
        <STATUS>3</STATUS>
    </HPAY>
</TRANS>

Now I need to turn these in to variables, and now I am scratching my head at how to do this.

Edit, tried pasting browser source here but it keeps changing it. However, to answer a previous comment, it is an xml response

  • 写回答

2条回答 默认 最新

  • doutan4831 2013-06-11 19:25
    关注

    Just Use SimpleXMLElement

    $xml = new SimpleXMLElement($data);
    $details = array();
    foreach($xml->HPAY->children() as $k => $v) {
        $details[$k] = "$v";
    }
    print_r($details);
    

    Output

    Array
    (
        [ID] => 223
        [MLABEL] => XXXX XXXX XXXX 9854
        [DATE] => 11/06/2013 21:00:36
        [SEN] => 
        [REC] => sc
        [DEB] => 0.00
        [CRED] => 10.34
        [COM] => 2.00
        [MSG] => 
        [STATUS] => 3
    )
    

    See Live DEMO

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?