Example #1
0
 /**
  * 获取天气信息
  */
 public function action_weather_data()
 {
     $city = $_GET['city'];
     if (!$city) {
         $city = \PinYIn::get(\IpSource::get());
         if (\in_array($city, array('LAN', 'Local IP', 'Invalid IP Address'))) {
             $city = 'shanghai';
         }
     }
     $view = new \View('admin/desktop/weather_data');
     $view->weather = Weather::get($city);
     $view->city = $city;
     $view->render();
 }
Example #2
0
 public static function get($str, $charset = 'UTF-8')
 {
     if (!$charset || ($charset = strtoupper($charset)) != 'GBK' || $charset != 'GB2312') {
         $str = iconv($charset, 'GBK', $str);
     }
     $ret = '';
     for ($i = 0; $i < strlen($str); $i++) {
         $p = ord(substr($str, $i, 1));
         if ($p > 160) {
             $q = ord(substr($str, ++$i, 1));
             $p = $p * 256 + $q - 65536;
         }
         $ret .= PinYIn::_g($p);
     }
     return $ret;
 }