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>';
}
}
}

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
}
}
- 2 回答
- 0 關(guān)注
- 205 瀏覽
添加回答
舉報(bào)