如何在Soap客户端输出PHP中仅获取XML
我正在使用一个使用soap客户端的web服务&它工作得很好。我的Soap客户端代码是:如何在Soap客户端输出PHP中仅获取XML,php,soap,Php,Soap,我正在使用一个使用soap客户端的web服务&它工作得很好。我的Soap客户端代码是: $wsdl = 'http://www.example.com/erpsync/erp_sync.asmx?WSDL'; $trace = true; $exceptions = false; $xml_array['userName'] = 'Admin'; $xml_array['password'] = 'admin@123'; $xml_array['ItemNo'] = '400500
$wsdl = 'http://www.example.com/erpsync/erp_sync.asmx?WSDL';
$trace = true;
$exceptions = false;
$xml_array['userName'] = 'Admin';
$xml_array['password'] = 'admin@123';
$xml_array['ItemNo'] = '4005002335910';
try
{
$client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' => $exceptions));
//$response = $client->GetAllItemData($xml_array);
$response = $client->GetAllItemStock($xml_array);
//$response = $client->GetStockByItem($xml_array);
//echo $client->__getLastRequest();
}
catch (Exception $e)
{
echo "Error!";
echo $e -> getMessage ();
echo 'Last response: '. $client->__getLastResponse();
}
var_dump($response);
输出如下所示:
object(stdClass)#2 (1) {
["GetAllItemStockResult"]=>
object(stdClass)#3 (1) {
["any"]=>
string(113098) "<ERPitems xmlns=""><ItemData><ItemCode>AG40-01811-I354 .....</ERPitems>"
}
}
在输出中,我希望消除标记前后的所有内容
怎么做?使用Preg\u match查找模式
$str = '<ERPitems xmlns=""><ItemData><ItemCode>AG40-01811-I354 .....</ERPitems>';
echo getTextBetweenTags($str, "ERPitems");
function getTextBetweenTags($string, $tagname)
{
$pattern = "/<$tagname.*?>(.*?)<\/$tagname>/";
preg_match($pattern, $string, $matches);
return $matches[1];
}
仅输出字符串的该部分?除非您计划为GetAllItemStockResult响应定义一个自定义类,该类自动解析xml格式的xml,否则我很难理解它与SOAP本身有什么关系。我不会定义任何自定义类。我试图找出这些数据在标记之前的来源。。。从你的var_dump,它转储你收到的对象。。。你可能想用$response->GetAllItemStockResult->any做点什么。非常感谢。这是有用的如果这是你正在寻找的答案,那么请标记它已回答。