dongyi6845
2013-06-11 19:16
浏览 129

将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

图片转代码服务由CSDN问答提供 功能建议

我是curl和xml的菜鸟,但我搜索了这个网站和网页以获得答案, 我找不到任何工作。

我使用cURL发送XML,收件人服务正确地获取数据并创建我收到的响应。 响应从 curl_exec 回显为 <前> &lt; TRANS&gt; &lt; HPAY&gt; &lt; ID&gt; 223&lt; / ID&gt; ; &lt; MLABEL&gt; XXXX XXXX XXXX 9854&lt; / MLABEL&gt; &lt; DATE&gt; 11/06/2013 21:00:36&lt; / DATE&gt; &lt; SEN&gt;&lt; / SEN&gt; &lt; REC&gt; sc&lt; / REC&gt; &lt; DEB&gt; 0.00&lt; / DEB&gt; &lt; CRED&gt; 10.34&lt; / CRED&gt; &lt; COM&gt; 2.00&lt; / COM&gt; &lt; MSG&gt;&lt; ; / MSG&gt; &lt; STATUS&gt; 3&lt; / STATUS&gt; &lt; / HPAY&gt; &lt; / TRANS&gt;

现在我需要转弯 这些变量,现在我正在摸索如何做到这一点。

编辑,尝试粘贴浏览器源,但它不断更改它。 但是,要回答之前的评论,它是一个xml响应

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dotdx80642 2013-06-11 19:22

    You need to extract the data with XML parser like xpath

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题