跪求英文版的天气预报 一个网站需要用到英文版的天气预报固定城市哪位大大有的话共享下啊找了大半天都是中文版的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 国内城市还是国外的?国外的有很多API,国内城市好像没有。 看到有人推荐yahoo的,先参考下,我也没弄过http://stackoverflow.com/questions/1822650/yahoo-weather-api-woeid-retrieval/1825167#1825167 你试试翻一下,写多少个replace 唠叨大大发过一个汉字转拼音的类唯一的问题可能就是这个类产生的是带平仄的拼音这个黑点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 ";//加了个空格,要不要自己决定 }} 别跪了,yahoo有的吧。http://developer.yahoo.com/weather/具体自己研究吧。 天气预报api楼主可以看看这个参数language string 语言。参数值3种可选:zh-chs(简体中文), zh-cht(繁体中文), en(英文) PHP 使用SESSION用户登陆后注销不了! 帮解密个DeZend加密文件 $_obfuscate_混稀 的 关于数据库设计 mysql 子查询后左联接遇到了问题。 php如何删除非html里面的注释? 平时做网站经常要用正则表达式--引自LAMP 兄弟连廖学杰 在网页中群发邮件并实时返回值 这么漂亮,怎么做的?一定要搞清楚! 有没有可能一个form同时提交到两个PHP文件处理? javascript中字符替换用何涵数? PHP从右向左截取字符串 php 获取远程文件 保存本地 一般用哪种方法
国外的有很多API,国内城市好像没有。
http://stackoverflow.com/questions/1822650/yahoo-weather-api-woeid-retrieval/1825167#1825167
唯一的问题可能就是这个类产生的是带平仄的拼音这个黑点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 ";//加了个空格,要不要自己决定
}
}
http://developer.yahoo.com/weather/
具体自己研究吧。