Exemple #1
1
function getGeo($ip)
{
    $geoplugin = new geoPlugin();
    $geoplugin->locate($ip);
    $geoip = geoip_record_by_name($ip);
    $geo = false;
    if (!empty($geoip)) {
        $geoip = array2object($geoip);
        // geoip delivers (sometimes)the strings in ISO-8859-1, convert non utf-8 into  UTF8 ( not UTF-8 )
        foreach ($geoip as $key => $val) {
            if (in_array($key, array('city', 'country_name'))) {
                $encoding = mb_detect_encoding($geoip->{$key});
                if ($encoding != 'UTF-8') {
                    $geoip->{$key} = iconv($encoding, 'UTF8//IGNORE', $geoip->{$key});
                }
            }
        }
        $geo = normalize_geo(false, $geoplugin);
        utf8_encode_deep($geo);
    }
    return $geo;
}
/**
 * Vue webservice[vue]
 *
 * @project	   plum.mvc
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Thierry Bogusz <*****@*****.**>
*/
function utf8_encode_deep($input)
{
    $output = array();
    //car $inut peut etre array()
    foreach ($input as $key => $value) {
        if (is_string($value)) {
            $value = utf8_encode($value);
        }
        if (is_string($key)) {
            $key = utf8_encode($key);
        }
        if (is_array($value)) {
            $value = utf8_encode_deep($value);
        }
        $output[$key] = $value;
    }
    return $output;
}
 function utf8_encode_deep(&$input)
 {
     if (is_string($input)) {
         $input = utf8_encode($input);
     } else {
         if (is_array($input)) {
             foreach ($input as &$value) {
                 utf8_encode_deep($value);
             }
             unset($value);
         } else {
             if (is_object($input)) {
                 $vars = array_keys(get_object_vars($input));
                 foreach ($vars as $var) {
                     utf8_encode_deep($input->{$var});
                 }
             }
         }
     }
 }