想要使用CURL在变量中获取xml响应值 [英] want to take xml response value in a variable using CURL
本文介绍了想要使用CURL在变量中获取xml响应值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< test xmlns:在浏览器中打开URL / API,并从服务器获取xml响应。 taxInfoDto =com.message.TaxInformationDto>
< response>
< code> 0000< / code>
< description> SUCCESS< / description>
< / response>
< accounts>
< account currency =BDTaccAlias =6553720>
< currentBalance> 856.13< / currentBalance>
< availableBalance> 856.13< / availableBalance>
< / account>
< / accounts>
< transaction>
< principalAmount> 0< / principalAmount>
< feeAmount> 0.00< / feeAmount>
< transactionRef> 2570277672< / transactionRef>
< externalRef />
< dateTime> 09/03/2016< / dateTime>
< userName> 01823074838< / userName>
< taxInformation totalAmount =0.00/>
< additionalData />
< / transaction>
< / test>
我使用下面的php代码获取响应....
<?php
$ ch = curl_init();
//设置网址和其他适当的选项
curl_setopt($ ch,CURLOPT_URL,http:// xxxx:/ ussd / process?destination = BANGLA& userName =& secondarySource = 01 );
curl_setopt($ ch,CURLOPT_HEADER,0);
$ retValue = curl_exec($ ch);
return $ retValue;
?>
我只获得如下输出的值。
0000SUCCESS856.13 856.13 00.00257027769109 / 03/201601823074838
但我喜欢分配一个变量中的每个值,并希望打印它。
例如
code = 0000
description = SUCCESS
currentBalance = 856.13 $ b $ 解决方案 div> 我相信你正在浏览浏览器中的cURL请求的输出:你需要转义你的输出,以防止浏览器解释为HTML / XML,因此应用 htmlentities
在输出上显示它之前:
curl_setopt($ curl,CURLOPT_RETURNTRANSFER,1);
....
return htmlentities($ retValue);
i am hitting a URL/API in browser and getting below xml response from the server.
<test xmlns:taxInfoDto="com.message.TaxInformationDto">
<response>
<code>0000</code>
<description>SUCCESS</description>
</response>
<accounts>
<account currency="BDT" accAlias="6553720">
<currentBalance>856.13</currentBalance>
<availableBalance>856.13</availableBalance>
</account>
</accounts>
<transaction>
<principalAmount>0</principalAmount>
<feeAmount>0.00</feeAmount>
<transactionRef>2570277672</transactionRef>
<externalRef/>
<dateTime>09/03/2016</dateTime>
<userName>01823074838</userName>
<taxInformation totalAmount="0.00"/>
<additionalData/>
</transaction>
</test>
i am using below php code to get the response....
<?php
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://x.x.x.x:/ussd/process? destination=BANGLA&userName=&secondarySource=01");
curl_setopt($ch, CURLOPT_HEADER, 0);
$retValue = curl_exec($ch);
return $retValue;
?>
i am getting only value as a output like below.
0000SUCCESS856.13 856.13 00.00257027769109/03/201601823074838
But i like to assign every value in a variable and want to print it.
such as
code=0000
description=SUCCESS
currentBalance=856.13
anyone please help.
解决方案 I believe you're looking at the output of the cURL request in a browser: you need to escape your output to prevent the browser from interpreting it as HTML/XML, so apply htmlentities
on the output before displaying it as in:
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
....
return htmlentities($retValue);
这篇关于想要使用CURL在变量中获取xml响应值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文