想要使用 CURL 在变量中获取 xml 响应值


want to take xml response value in a variable using CURL

我在浏览器中点击了URL/API,并从服务器获得了低于xml的响应。

<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>

我正在使用下面的PHP代码来获取响应....

<?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;
?>

我只得到如下所示的输出值。

0000SUCCESS856.13 856.13 00.00257027769109/03/201601823074838

但是我喜欢分配变量中的每个值并想要打印它。如

code=0000
description=SUCCESS
currentBalance=856.13

任何人请帮忙。

我相信您正在浏览器中查看 cURL 请求的输出:您需要转义输出以防止浏览器将其解释为 HTML/XML,因此htmlentities在将其显示为 in:

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
....
return htmlentities($retValue);