2016-12-22 36 views
-1

Michael請求編輯的帖子。strstr - 對XML響應無法正常工作(符號)

$Response = $soapClient->__getLastResponse(); 
$pos = strpos($Response, ">"); 
echo substr($Response, $pos+1); 
// Returns soap:ReceiverServer was unable to process request. ---> Product already exists 

$Response = $soapClient->__getLastResponse(); 
$converted = (string)$Response 
$pos = strpos($converted, ">"); 
echo substr($converted, $pos+1); 
// Returns soap:ReceiverServer was unable to process request. ---> Product already exists 

我使用的API,並想要使用響應爲錯誤消息。響應如下所示:

soap:ReceiverServer was unable to process request. ---> Product already exists

我試圖刪除之前的一切Product所以我只是有個錯誤信息顯示給用戶。但是,當我使用這個,我得到以下回報。

>soap:ReceiverServer was unable to process request. ---> Product already exists

這是我目前使用的代碼。有人有任何建議嗎?

$Response = $soapClient->__getLastResponse(); 
echo $Response; 
// Shows the below 
// soap:ReceiverServer was unable to process request. ---> Product already exists 

$test = strstr($Response, '>'); 
echo '<br>' 
echo $test; 
// Shows the below 
// >soap:ReceiverServer was unable to process request. ---> Product already exists 

回答

0
$Response = "soap:ReceiverServer was unable to process request. --- > Product already exists"; 
$pos = strpos($Response, ">"); 
echo substr($Response, $pos+1); 
+0

嗨@邁克爾這將返回以下'肥皂:ReceiverServer無法處理請求。 --->產品已經存在了' – Jake

+0

這很奇怪...看一看php沙盒: http://sandbox.onlinephpfunctions.com/code/0a239f502623c69f88d81a2f0c74e665f3d55171 – Michael

+0

你可以粘貼你的代碼和我建議的修改嗎? – Michael