Reputation: 13
I have a PHP webservice that returns the following
$response = $client->submit($requestParams);
stdClass Object
(
[return] => stdClass Object
(
[result_code] => 0
[result_data] => City=Chicago
[message_text] =>
)
)
What I want is not to assign [result_data] => City=Chicago
to a variable like
$city = [result_data] => City=Chicago
so that
$city = Chicago;
So be clear if I do a print_r($response) I get
stdClass Object
(
[return] => stdClass Object
(
[result_code] => 0
[result_data] => City=Chicago
[message_text] =>
)
)
from this I only want the value for [result_data] in this example that value would be the string "City=Chicago"
Upvotes: 0
Views: 204
Reputation: 34426
Here is one way to do it -
$arrRD = explode('=',$response->return->result_data); // separates the City=Chicago string into an array
$city = $arrRD[1]; // 'Chicago' is the second part of the array
EDIT: PhpFiddle - http://phpfiddle.org/main/code/8ut6-mtg3
Upvotes: 0
Reputation: 3555
If City=Chicago
is a string you can do this:
$response = new stdClass(); // this is a sample object taking your example
$response->result_code = 0;
$response->result_data = 'City=Chicago';
$response->message_text = '';
$result = explode('=', $response->result_data);
${$result[0]} = $result[1]; // or $City = $result[1];
echo $City;
Hope this works for you :)
Upvotes: 1