This article mainly introduces the IP call Sina API to get the city name and converted to Pinyin example, the need for friends can refer to the following
Function: 1, get current IP address, 2, call Sina API, get to the current city. 3, convert the Chinese to pinyin and then jump. Code as follows: <?php include './pinyin.php '; //Get current IP function GetIP () { $ONLINEIP = '; if (getenv (' http_client_ip ') &&strcasecmp getenv ( ' Http_client_ip '), ' unknown ') { $onlineip =getenv (' http_client_ip '); } elseif (getenv (' Http_x_ Forwarded_for ') &&strcasecmp (getenv (' http_x_forwarded_for '), ' unknown ')) { $onlineip =getenv (' Http_x_forwarded_for '); } elseif (getenv (' remote_addr ') &&strcasecmp (getenv (' remote_addr '), ' unknown ')) { $ Onlineip=getenv (' remote_addr '); } elseif (Isset ($_server[' remote_addr ')) &&$_server[' remote_addr ']&&strcasecmp ($_server[' Remote_ ADDR '], ' unknown ') { $ONLINEIP =$_server[' remote_addr ']; } return $ONLINEIP; &NBSP} //get the city Information API function GetLocation ($IP) { $curl = Curl_init (); curl_setopt ($curl, C Urlopt_url, "Http://int.dpool.sina.com.cn/iplookUp/iplookup.php?format=json&ip= ". $ip); curl_setopt ($curl, Curlopt_returntransfer, 1); curl_setopt ($curl, Curlopt_connecttimeout, 30); $STR = curl_exec ($curl); Curl_close ($curl); return $STR; &NBSP} //current IP address $currentIP = GetIP (); //through the current IP access information $getLocation = getLocation ($currentIP); $currentInfo = Json_decode ($getLocation, True); //determine if IP is a valid if ($currentInfo [' ret '] = = ' -1 ') { $currentInfo [' city '] = ' unknown ';  } //current urban Chinese name $currentCityName = $CURRENTINF o[' City ']; $currentCityEName = $pin->pinyin ("$currentCityName", ' UTF8 '); //City Pinyin pronunciation switch ($currentCityEName) { case ' zhongqing ': $currentCityEName = ' Chongqing '; break; case ' Shenfang ': $currentCityEName = ' Shifang '; break; case ' Chengdou ': $currentCityEName = ' Chengdu ';   Break case ' Yueshan ': $currentCityEName = ' Leshan '; break; case ' Junxian ': $currentCityEName = ' Xunxian '; break; case ' shamen ': $currentCityEName = ' Xiamen '; break; case ' Zhangsha ': $currentCityEName = ' Changsha '; break; case ' Weili ': $currentCityEName = ' Yuli '; break; case ' Zhaoyang ': $currentCityEName = ' Chaoyang '; break; case ' Danxian ': $currentCityEName = ' Shanxian '; break; Default: $currentCityEName = $pin->pinyin ("$currentCityName", ' UTF8 '); break; &NBSP} //redirect browser header ("location:http://www.jb51.net"); exit;