php - Max MInd Omni Web Service Array into Variables -


hi using max mind omni web service , using php example code.

i new using curl , trying find out best way seperate array in individual variables can insert database table.

below example of code using. when run code can not seem individual value of omni keys.

any suggestions appreciated.

 if (!isset($params['i'])) $params['i'] = '82.150.248.29';   $query = 'https://geoip.maxmind.com/e?' . http_build_query($params);   $omni_keys =     array(     'country_code',     'country_name',     'region_code',     'region_name',     'city_name',     'latitude',     'longitude',     'metro_code',     'area_code',     'time_zone',     'continent_code',     'postal_code',     'isp_name',     'organization_name',     'domain',     'as_number',     'netspeed',     'user_type',     'accuracy_radius',     'country_confidence',     'city_confidence',     'region_confidence',     'postal_confidence',     'error'     );     $curl = curl_init();    curl_setopt_array( $curl,                 array(                      curlopt_url => $query,                      curlopt_useragent => 'maxmind php sample',                      curlopt_returntransfer => true                      )                );              $resp = curl_exec($curl);            if (curl_errno($curl)) {             throw new exception('geoip request failed');               }                    $omni_values = str_getcsv($resp);                 $omni = array_combine( $omni_keys, $omni_values);                  //print_r($omni_values);                   $country_code=$omni_value[0];                  $country_name=$omni_value[1];                  echo "$country_code";                  echo "$country_name"; 

there's typo in code....

$country_code= $omni_values[0]; //instead of $omni_value[0]; 

this line in makes associative array.

$omni = array_combine( $omni_keys, $omni_values); 

so you'll make few changes so:

$country_code= $omni['country_code']; //instead of $omni_value[0]; $country_name= $omni['country_name']; //instead of $omni_value[1];    

hope helps


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -