Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extracting variable values from object

Status
Not open for further replies.

parktek08

IS-IT--Management
Dec 7, 2008
13
I am connecting to a web service thru soap client like
$results = $client->search(array("developerKey" => $developerKey,
"websiteId" => $websiteId,
"advertiserSku" => 'N82E16858191069'));

print_r($results);

this outputs something like this to my browser:

stdClass Object ( [out] => stdClass Object ( [count] => 1 [offset] => 0 [products] => stdClass Object ( [Product] => stdClass Object ( [adId] => 10440897 [advertiserId] => 182344 [advertiserName] => test.com [buyUrl] => [catalogId] => cjo:1460 [currency] => USD [description] => MLAN [imageUrl] => [inStock] => [isbn] => [manufacturerName] => N [manufacturerSku] => 980-0054-R01 [name] => America [price] => 9 [retailPrice] => 0 [salePrice] => 9.99 [sku] => 1069 [upc] => ) ) [totalResults] => 1 ) )

I want to be able to retrieve the values of invidual variables [buyUrl] or [advertiserName] as string and insert in to db. I have tried many things like get_object_vars, extract, and few other things but nothing seems to work. any help would be appreicated. thanks
 
Looks to me like that's just a standard array, so something like this should work for you:

$buyURl=$results['buyURL'];

$advertiserName=$results['advertiserName'];

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
nope. I tried that and it comes back with this:
Fatal error: Cannot use object of type stdClass as array
 
I tried
print_r ($results->buyUrl);
print_r ($results->advertiserName);
which does not output anything on the browser.
 
actually i think the object is a bit more complex than it looks at first glance.

the data looks to be a couple of object-layers deep

Code:
$advertiserName = $results->products->product->advertiserName
$buyUrl = $results->products->product->buyUrl;
 
Hi

Nice catch, jpadie. However I count one more level there :
Code:
$advertiserName = $results[red]->out[/red]->products->Product->advertiserName;
$buyUrl = $results[red]->out[/red]->products->Product->buyUrl;
parktek08, in the future please do not post structured data as character flow. Use line breaks and indentation just as [tt]print_r()[/tt]] does.

Feherke.
 
Yikes!, how did I miss that? sorry about that.

That's what I get for looking at code before going to bed.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
thanks guys. it worked. ie outputs that objects the same way I pasted. it looks like a long string. but if I view source html of the output page then it displays it as structured object. I will be more carefull next time.
thanks for your response and time.
 
html is white space agnostic. if you want the object to look nice on the page surround the output in <pre> tags
Code:
echo "<pre>".print_r($obj, true) . "</pre>";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top