一个网站需要用到英文版的天气预报
固定城市
哪位大大有的话共享下啊
找了大半天都是中文版的

解决方案 »

  1.   

    国内城市还是国外的?
    国外的有很多API,国内城市好像没有。
      

  2.   

    看到有人推荐yahoo的,先参考下,我也没弄过
    http://stackoverflow.com/questions/1822650/yahoo-weather-api-woeid-retrieval/1825167#1825167
      

  3.   

    你试试翻一下,写多少个replace
      

  4.   

    唠叨大大发过一个汉字转拼音的类
    唯一的问题可能就是这个类产生的是带平仄的拼音这个黑点gif图是源码之一,下来之后和php文件放到一起
    php代码:
    <?php 
    class Tpinyin {
      protected $dict = array();
      protected $dictfile = 'pylib.gif';
      protected $dictoffs = 244;
      protected $tune = array();
      private $charset = '';
      private $maxlength = 0;
      private $fp;
      function __construct() {
    $root = $_SERVER['DOCUMENT_ROOT']."IC_DataAnalysis/class/pinyin/pylib.gif";
        //$fp = fopen($this->dictfile, 'rb');
    $fp = fopen($root, 'rb');
        fread($fp, 41);
        $this->dict[] = explode(',', fread($fp, 57));
        $this->dict[] = explode(',', fread($fp, 146));
      }
      
      public function settune() {
        $tune = array(
            'a' => array("\x01\x01","\x00\xe1","\x01\xce","\x00\xe0",),
            'e' => array("\x01\x13","\x00\xe9","\x01\x1b","\x00\xe8",),
            'i' => array("\x01\x2b","\x00\xed","\x01\xd0","\x00\xec",),
            'o' => array("\x01\x4d","\x00\xf3","\x01\xd2","\x00\xf2",),
            'u' => array("\x01\x6b","\x00\xfa","\x01\xd4","\x00\xf9",),
            'v' => array("\x01\xd6","\x01\xd8","\x01\xda","\x01\xdc",),
            );
        foreach($tune as $k=>$r)
            foreach($r as $i=>$v)
                $this->tune[$k][$i] = mb_convert_encoding($v, $this->charset, 'UCS-2');
      }
      
      public function pinyin($str) {
        $this->charset = mb_check_encoding($str, 'UTF-8') ? 'UTF-8' : 'GBK';
        $this->settune();
       $root = $_SERVER['DOCUMENT_ROOT']."IC_DataAnalysis/class/pinyin/pylib.gif";
        //$fp = fopen($this->dictfile, 'rb');
    $this->fp = fopen($root, 'rb');
        //$this->maxlength = filesize($this->dictfile);
        $this->maxlength = filesize($root);
        $str = mb_convert_encoding($str, "UCS-2", "UTF-8, GBK");
        $t = array_map(array($this, 'pinyin_back'), str_split($str, 2));
        return join('', $t); //连接成串,要不要自己决定
      }
      
      public function pinyin_back($ch) {
        if(ord($ch{0}) == 0) return $ch{1};
        $o = hexdec(bin2hex($ch)) - 0x4e00;
        if($o < 0 || $o >= $this->maxlength) return mb_convert_encoding($ch, $this->charset, 'UCS-2');
        fseek($this->fp, $o*2 + $this->dictoffs);
        $x = sprintf('%05d', current(unpack('S', fread($this->fp, 2))));
        $t = $this->dict[0][substr($x, 0, 2)+0] . $this->dict[1][substr($x, 2, 2)+0];
        $n = substr($x, -1) - 1;
        $s = $t;
        foreach($this->tune as $k=>$v) {
            $s = str_replace($k, $v[$n], $s);
            if($s != $t) break;
        }
        return "$s ";//加了个空格,要不要自己决定
      }
    }
      

  5.   

    别跪了,yahoo有的吧。
    http://developer.yahoo.com/weather/
    具体自己研究吧。
      

  6.   

    天气预报api楼主可以看看这个参数language string 语言。参数值3种可选:zh-chs(简体中文), zh-cht(繁体中文), en(英文)