Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将Sabre SOAP API响应转换为PHP数组_Php_Sabre - Fatal编程技术网

如何将Sabre SOAP API响应转换为PHP数组

如何将Sabre SOAP API响应转换为PHP数组,php,sabre,Php,Sabre,我得到的Sabre SOAP API响应类似于: <soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> <soap-env:header></soap-env:header> <soap-env:body> <ota_airlowfaresearchrs xmlns="http://www.opentravel.or

我得到的Sabre SOAP API响应类似于:

<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:header></soap-env:header>
    <soap-env:body>
    <ota_airlowfaresearchrs xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.1.0" priceditincount="50" brandedonewayitincount="0" simpleonewayitincount="0" departeditincount="0" soldoutitincount="0" availableitincount="0">
    <success>
    <priceditineraries><priceditinerary sequencenumber="1"></priceditinerary>
    <priceditinerary sequencenumber="2"></priceditinerary></priceditineraries>
    </success>
    </ota_airlowfaresearchrs>
    </soap-env:body>
</soap-env:envelope>
它返回空数组,如:
simplexmlement对象()

From

$parser = simplexml_load_string($res); 
您必须进行如下更改:

$parser = simplexml_load_string($res, "SimpleXMLElement", LIBXML_NOCDATA);
LIBXML\u NOCDATA:您可以使用此函数调用让simplexml将CDATA转换为纯文本。

参考:

我通过以下方法得到了答案:

$soap     = simplexml_load_string($res);
$response = $soap->children('http://schemas.xmlsoap.org/soap/envelope/')
                 ->body->children()
                 ->ota_airlowfaresearchrs
                 ->success
                 ->priceditineraries

无论如何谢谢@lalithkumar

你有什么错误吗?只是一个空数组。没问题。我会像这样保留这个答案。它可能会对某人有所帮助。
$soap     = simplexml_load_string($res);
$response = $soap->children('http://schemas.xmlsoap.org/soap/envelope/')
                 ->body->children()
                 ->ota_airlowfaresearchrs
                 ->success
                 ->priceditineraries