strstr - Not working correctly with XML Response (Symbols)

76 views Asked by At

Edited post requested by Michael.

$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

I am using an API and wanting to use the response as an error message. The response looks like the following:

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

I am trying to remove everything before Product so I just have the error message to display to a user. However when I use this, I get the following in return.

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

This is the code I am currently using. Does anybody have any suggestions?

$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
1

There are 1 answers

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