亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 PHP 中將 XML 轉換為數組

如何在 PHP 中將 XML 轉換為數組

PHP
DIEA 2023-06-18 16:17:37
我是 SOAP API 的新手,我得到了 Web 服務的響應。但我無法將其轉換為數組以獲取密鑰。<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">   <soap:Body>      <ns2:setTransactionResponse xmlns:ns2="http://soap.api.controller.web.payjar.com/">         <return>            <merchantReference>mercRef_1395758213</merchantReference>            <payUReference>17613281409117</payUReference>            <successful>true</successful>         </return>      </ns2:setTransactionResponse>   </soap:Body></soap:Envelope>
查看完整描述

1 回答

?
慕桂英546537

TA貢獻1848條經驗 獲得超10個贊

嘗試以下對數組的 xml 響應


 $xml = $response;

$xml = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $xml);

$xml = simplexml_load_string($xml);

$json = json_encode($xml);

$responseArray = json_decode($json,true);




echo "<pre>";print_r($responseArray);

輸出


Array

(

    [soapBody] => Array

        (

            [ns2setTransactionResponse] => Array

                (

                    [return] => Array

                        (

                            [merchantReference] => mercRef_1395758213

                            [payUReference] => 17613281409117

                            [successful] => true

                        )


                )


        )


)


查看完整回答
反對 回復 2023-06-18
  • 1 回答
  • 0 關注
  • 160 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號