troubleshooting Question

Get variable values inside function

Avatar of Pedro Chagas
Pedro ChagasFlag for Portugal asked on
5 Comments2 Solutions624 ViewsLast Modified:
Hi E's, In snippet code you can see the code I use for get keywords from google adwords api.
In the last lines you can see the variable that contains the keywords: "$service->response;".
If I change the last lines for:
function show_xml($service) {
  $newwords = $service->response; //remove echo $service->response;
echo $newwords; //view the values out of function
The system don't give me any keywords, so I thing is because I just can see the keywords if I execute "echo $newwords;" inside the function.
But if I want get the values inside "$service->response;" out of the function, how I do?

Regards, JC
$email = '++++++++++++++++';
$password = '++++++++++';
$useragent = 'INSERT_COMPANY_NAME: AdWords API PHP Sample Code';
$developer_token = '++++++++++++++++';
$application_token = '++++++++++++++++++';
$headers =
  '<email>' . $email . '</email>'.
  '<password>' . $password . '</password>' .
  '<clientEmail>' . $client_email . '</clientEmail>' .
  '<useragent>' . $useragent . '</useragent>' .
  '<developerToken>' . $developer_token . '</developerToken>' .
  '<applicationToken>' . $application_token . '</applicationToken>';
$namespace = '';
$keyword_tool_service = SoapClientFactory::GetClient(
  $namespace . '/KeywordToolService?wsdl', 'wsdl');
$debug = 1;
$seed_keyword =
  '<negative>false</negative>' .
  '<text>'.$_GET['texto'].'</text>' .
$use_synonyms = '<useSynonyms>true</useSynonyms>';
$request_xml =
  '<getKeywordVariations>' .
  '<seedKeywords>' . $seed_keyword . '</seedKeywords>' .
  $use_synonyms .
  '<languages>pt</languages>' .
  '<countries>PT</countries>' .
  '<countries>BR</countries>' .
$variation_lists =
  $keyword_tool_service->call('getKeywordVariations', $request_xml);
$variation_lists = $variation_lists['getKeywordVariationsReturn'];
if ($debug) show_xml($keyword_tool_service);
if ($keyword_tool_service->fault) show_fault($keyword_tool_service);
$to_consider = $variation_lists['additionalToConsider'];
($to_consider) .
  ' variation(s).' . "\n";
$more_specific = $variation_lists['moreSpecific'];
($more_specific) .
  ' variation(s).' . "\n";
function show_xml($service) {
  echo $service->response;
  echo "\n";  
Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros