如何将此响应从nusoap解析为php变量/数组

如何将此响应从nusoap解析为php变量/数组,php,xml,arrays,soap,nusoap,Php,Xml,Arrays,Soap,Nusoap,因此,在设法让nusoap轮询chemspider服务器以获取信息后,我得到了一个响应,该响应将使用print\r显示,但当使用print时,将只显示数组 我的问题是,如何将给定的响应转换为php数组 nusoap客户端的代码 <?php require_once('../lib/nusoap.php'); $client = new nusoap_client('http://www.chemspider.com/Search.asmx?WSDL', 'wsdl'); $err = $c

因此,在设法让nusoap轮询chemspider服务器以获取信息后,我得到了一个响应,该响应将使用print\r显示,但当使用print时,将只显示数组

我的问题是,如何将给定的响应转换为php数组

nusoap客户端的代码

<?php
require_once('../lib/nusoap.php');
$client = new nusoap_client('http://www.chemspider.com/Search.asmx?WSDL', 'wsdl');
$err = $client->getError();
if ($err) {
    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$query = 'methanol';
$token = 'token';
$result = $client->call(SimpleSearch, array('query' => $query, 'token' => $token), array('return' => 'xsd:string'), "http://www.chemspider.com/SimpleSearch") ;
// Check for a fault
if ($client->fault) {
    echo '<h2>Fault</h2><pre>';
    print_r($result);
    echo '</pre>';
} else {
    // Check for errors
    $err = $client->getError();
    if ($err) {
    // Display the error
    echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
    // Display the result
    echo '<h2>Result</h2><pre>';
    print_r($result);
    echo '</pre>';
}
}



echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
这将提供以下输出减去调试信息:


您想解析$client->响应吗?尝试分解“\n”、$client->response并分解“:”、$each_string

在您使用的脚本中,响应已解析为一个名为$result的PHP数组。您已经在输出中打印了数组

据我所知,您的问题是打印和回送在阵列上无法正常工作。它们只是输出类型数组而不是内容

您可以使用调用$result的输出


您可以在中阅读有关PHP数组处理的更多信息。

您的问题似乎是错的。您已经有了一个完全可用的数组,即$result。您的问题似乎是,当我回显$result;,它为什么会输出“Array”?。请看下面我给出的答案。我只是很难理解是什么导致了这个问题。谢谢你的建议,虽然下面的建议解决了这个问题。谢谢你的努力
Result

Array
(
    [SimpleSearchResult] => Array
        (
           [int] => 864
        )

 )

Request

POST /Search.asmx HTTP/1.0
Host: www.chemspider.com
User-Agent: NuSOAP/0.7.3 (1.114)
Content-Type: text/xml; charset=ISO-8859-1
SOAPAction: "http://www.chemspider.com/SimpleSearch"
Content-Length: 489

<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns8284="Array"><SOAP-ENV:Body><SimpleSearch xmlns="http://www.chemspider.com/"><query>methanol</query><token>token</token></SimpleSearch></SOAP-ENV:Body></SOAP-ENV:Envelope>

Response

HTTP/1.1 200 OK
x-cspc-fd: search.asmx
x-cspc-fh: chemspider
x-orig-path: /Search.asmx
Set-Cookie: x-dsp=
Set-Cookie: x-d-ond=dond
Set-Cookie: X-Mapping-kckcchol=47DE43E9D82204D9CDBBD4A2610306B8; path=/
Cache-Control: private, max-age=0
x-cspc-pl: 0
Content-Length: 381
x-cspc-hs: chemspider.com
Date: Thu, 24 Sep 2009 08:54:01 GMT
 x-bwcc: pub
 x-dsp: [][]
Connection: close
X-AspNet-Version: 2.0.50727
x-cspc-pt: /Search.asmx
Z-Spider: Hunstman-32-1
x-orig-host: chemspider.com
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Content-Type: text/xml; charset=utf-8

<?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><SimpleSearchResponse xmlns="http://www.chemspider.com/"><SimpleSearchResult><int>864</int></SimpleSearchResult></SimpleSearchResponse></soap:Body></soap:Envelope>
print $result['simpleSearchResult']['int'] // Will display 864