Pedro Chagas
asked on
Get variable values inside function
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
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
include('soapclientfactory.php');
$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 = 'https://adwords.google.cn/api/adwords/v12';
$keyword_tool_service = SoapClientFactory::GetClient(
$namespace . '/KeywordToolService?wsdl', 'wsdl');
$keyword_tool_service->setHeaders($headers);
$debug = 1;
$seed_keyword =
'<negative>false</negative>' .
'<text>'.$_GET['texto'].'</text>' .
'<type>Exact</type>';
$use_synonyms = '<useSynonyms>true</useSynonyms>';
$request_xml =
'<getKeywordVariations>' .
'<seedKeywords>' . $seed_keyword . '</seedKeywords>' .
$use_synonyms .
'<languages>pt</languages>' .
'<countries>PT</countries>' .
'<countries>BR</countries>' .
'</getKeywordVariations>';
$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";
}
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
In line 38, you call a function named "show_fault()", but this function is not defined. Define it, or don't call it! You can try this:
if ($keyword_tool_service->fa ult) var_dump($keyword_tool_ser vice->faul t);
if ($keyword_tool_service->fa
ASKER
Forget @cxr, your code is correct, I'm sory.
Regards, JC
Regards, JC
ASKER
$to_consider = $variation_lists['addition
($to_consider) .
' variation(s).' . "\n";
$more_specific = $variation_lists['moreSpec
($more_specific) .
' variation(s).' . "\n";
FOR-----------------------
$to_consider = $variation_lists['addition
echo ($to_consider) .
' variation(s).' . "\n";
$more_specific = $variation_lists['moreSpec
echo ($more_specific) .
' variation(s).' . "\n";
I change too:
function show_xml($service) {
echo $service->response;
echo "\n";
}
FOR-----------------------
function show_xml($service) {
return $service->response;
}
$newwords = show_xml($keyword_tool_ser
echo $newwords;
I get a error "Fatal error: Call to undefined function show_fault() in /home/tags/public_html/bas
Line 38 is: "if ($keyword_tool_service->fa
Please tell me what is wrong.
Regards, JC
Open in new window