sanchez77 Posted March 8, 2012 Share Posted March 8, 2012 Curious how to set a returned value from a web service to a php variable? $tid= $_POST['tid']; $client = new SoapClient("http://www.sitename.com/WebSvc.asmx?WSDL"); $result = $client->getName(array('tid'=>$tid)); echo json_encode($result); Returns this: {"getNameResult":{"count":1,"results":{"TaggedText":{"tid":"001","text":"John Smith"}}}} How do I set a php variable $RetName to equal John Smith? I tried $RetName = $text; But that didn't work. Any help is apprecaited. Thanks, sanchez Quote Link to comment https://forums.phpfreaks.com/topic/258541-web-service-soap-set-php-variable/ Share on other sites More sharing options...
batwimp Posted March 8, 2012 Share Posted March 8, 2012 What do you get if you var_dump($result)? Quote Link to comment https://forums.phpfreaks.com/topic/258541-web-service-soap-set-php-variable/#findComment-1325303 Share on other sites More sharing options...
sanchez77 Posted March 8, 2012 Author Share Posted March 8, 2012 object(stdClass)#9 (1) { ["getNameResult"]=> object(stdClass)#10 (2) { ["count"]=> int(1) ["results"]=> object(stdClass)#11 (1) { ["TaggedText"]=> object(stdClass)#12 (2) { ["tid"]=> string(3) "001" ["text"]=> string(11) "John Smith" } } } } Quote Link to comment https://forums.phpfreaks.com/topic/258541-web-service-soap-set-php-variable/#findComment-1325307 Share on other sites More sharing options...
batwimp Posted March 8, 2012 Share Posted March 8, 2012 So try: echo $result->getNameResult->results->TaggedText->text; Quote Link to comment https://forums.phpfreaks.com/topic/258541-web-service-soap-set-php-variable/#findComment-1325313 Share on other sites More sharing options...
sanchez77 Posted March 8, 2012 Author Share Posted March 8, 2012 That did it, thank you so much. Cheers, sanchez Quote Link to comment https://forums.phpfreaks.com/topic/258541-web-service-soap-set-php-variable/#findComment-1325330 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.