第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

需要從PHP中的cURL XML響應(yīng)中刪除標(biāo)頭

需要從PHP中的cURL XML響應(yīng)中刪除標(biāo)頭

PHP
慕桂英546537 2021-05-13 14:11:07
關(guān)于此有一些線程,但是我在其中找不到解決此問題的解決方案。我希望它不會違反重復(fù)的規(guī)則。我已經(jīng)使用靜態(tài)XML測試了以下代碼,并且效果很好,但是說XML不包含任何標(biāo)頭。我試圖在發(fā)出POST請求后通過代碼刪除標(biāo)頭,以便我可以繼續(xù)處理生成的XML,但是我對此沒有任何運(yùn)氣。這是XML:<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><AUTOS_Cotizar_PHPResponse xmlns="http://tempuri.org/"><AUTOS_Cotizar_PHPResult><auto xmlns=""><operacion>1555843</operacion><statusSuccess>TRUE</statusSuccess><statusText></statusText><cotizacion><cobertura><codigo>A0</codigo><descripcion>RESPONSABILIDAD CIVIL SOLAMENTE</descripcion><premio>928,45</premio><cuotas>01</cuotas><impcuotas>928,45</impcuotas></cobertura></cotizacion><datos_cotiz><suma>477250</suma><uso>901</uso></datos_cotiz></auto></AUTOS_Cotizar_PHPResult></AUTOS_Cotizar_PHPResponse></soap:Body></soap:Envelope>這是代碼://converting raw cURL response to XML$temp1 = htmlspecialchars ($reply); //replacing top headers$temp2 = str_replace('<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><AUTOS_Cotizar_PHPResponse xmlns="http://tempuri.org/"><AUTOS_Cotizar_PHPResult>', "<<<'EOD'", $temp1);//replacing closing header tags     echo $temp3;//simplexml conversion$xml = simplexml_load_string($temp3);//running through the array and printing all valuesif ($xml !== false) {    foreach ($xml->cotizacion as $cotizacion) {        foreach ($cotizacion->cobertura as $cobertura) {            echo $cobertura->codigo;            echo '<br>';            echo $cobertura->descripcion;            echo '<br>';            echo $cobertura->premio;            echo '<br>';            echo $cobertura->cuotas;            echo '<br>';            echo $cobertura->impcuotas;            echo '<br>';        }    }}可能有更有效的方法來執(zhí)行此操作,或者我可能沒有正確執(zhí)行此操作。我現(xiàn)在正要學(xué)習(xí),因此隨時(shí)可以以任何方式糾正我,我將不勝感激!
查看完整描述

2 回答

?
滄海一幻覺

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超5個(gè)贊

處理響應(yīng)字符串的方法不是一個(gè)好主意,您應(yīng)該堅(jiān)持將內(nèi)容作為XML處理并使用。這使用XPath查找處理數(shù)據(jù)的起點(diǎn)(我無法使用當(dāng)前示例進(jìn)行測試),但是應(yīng)該可以幫助您完成所需的工作...


// Load the original reply

$xml = simplexml_load_string($reply);


//running through the array and printing all values

if ($xml !== false) {

    // Find the <auto> element (use [0] as you want the first one)

    $auto = $xml->xpath("//auto")[0];


    // Loop through the cotizacion elements in the auto element

    foreach ($auto->cotizacion as $cotizacion) {

        foreach ($cotizacion->cobertura as $cobertura) {

            echo $cobertura->codigo;

            echo '<br>';

            echo $cobertura->descripcion;

            echo '<br>';

            echo $cobertura->premio;

            echo '<br>';

            echo $cobertura->cuotas;

            echo '<br>';

            echo $cobertura->impcuotas;

            echo '<br>';

        }

    }

}


查看完整回答
反對 回復(fù) 2021-05-28
?
慕哥6287543

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超10個(gè)贊

SOAP響應(yīng)仍然是XML文檔,因此請與其一起使用而不是與之抗?fàn)?。將其視為字符串絕對不是很好。


據(jù)我所知,您正在嘗試使用所有<cotizaction>元素。在XML文檔中查找元素很簡單。在XPath上閱讀。


$xml = simplexml_load_string(htmlspecialchars($reply));

if ($xml) {

    foreach ($xml->xpath('//cotizacion') as $cotizacion) {

        // do your thing

    }

}


查看完整回答
反對 回復(fù) 2021-05-28
  • 2 回答
  • 0 關(guān)注
  • 205 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號