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 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料