getSuggestions

Collects the suggestions or stops the script on Failure.

Description

(string) getSuggestions( (string) $p_str_Keyword, (string) $p_str_Language, (number) $p_str_Country ); 

Returns (string)

Parameters (3)

0. $p_str_keyword (string)
The p str Keyword.
1. $p_str_language (string)
The p str Language.
2. $p_str_country (number)
The p str Country.

Usage

  1. if ( !function_exists( 'getSuggestions' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-keyword-suggest/ajax.php'; 
  3.  
  4. // The p str Keyword. 
  5. $p_str_keyword = ''; 
  6.  
  7. // The p str Language. 
  8. $p_str_language = ''; 
  9.  
  10. // The p str Country. 
  11. $p_str_country = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = getSuggestions($p_str_keyword, $p_str_language, $p_str_country); 
  15.  

Defined (1)

The function is defined in the following location(s).

/ajax.php  
  1. function getSuggestions($p_str_Keyword, $p_str_Language, $p_str_Country) { 
  2. // get url 
  3. $l_str_Url = 'http://google.de/complete/search?output=toolbar&hl='.$p_str_Language.'&gl='.$p_str_Country.'&q='.$p_str_Keyword; 
  4. // get suggestions as XML 
  5. //$l_str_Response = file_get_contents($l_str_Url); 
  6.  
  7. $l_obj_Curl = curl_init(); 
  8. curl_setopt($l_obj_Curl, CURLOPT_URL, $l_str_Url); 
  9. curl_setopt($l_obj_Curl, CURLOPT_HEADER, 0); 
  10. curl_setopt($l_obj_Curl, CURLOPT_RETURNTRANSFER, 1); 
  11. $l_str_Response = curl_exec($l_obj_Curl); 
  12. $l_int_HttpStatus = curl_getinfo($l_obj_Curl, CURLINFO_HTTP_CODE); 
  13. curl_close($l_obj_Curl); 
  14.  
  15. // either no response received or Failure in request 
  16. if (empty($l_str_Response)) { 
  17. returnSuggestions('<li>' . sprintf(__("Error reading response from API. Response status: %d", GOOGLE_KS_INTERNAL_PLUGIN_NAME), $l_int_HttpStatus) . '</li>'); 
  18. return utf8_encode($l_str_Response);