採集天气编码问题
set_time_limit(0);
connect_sql();
$names = trim($_GET['names']);
$id = get_id($names);
if($id){
$url = 'http://m.weather.com.cn/data/'.$id.'.html';
$host = 'http://www.weather.com.cn/';
$files = @file_get_contents($url);
$data = json_decode($files);
$content_encoding = mb_detect_encoding($data, array('UTF-8', 'GBK'));
$datas = iconv($content_encoding, 'UTF-8//IGNORE', $data);
var_dump($data);
}
関数 get_id($names){
$sql = "SELECT city_bh FROM city_id WHERE city_name = '{$names}'";
$rel = mysql_query($sql);
$row = mysql_fetch_array($rel);
$id = $row['city_bh'];
$id を返す;
}
関数 connect_sql(){
$con = mysql_connect('localhost','root','123456') または die('mysql error :'.mysql_error());
mysql_select_db('テスト');
mysql_query('set names utf8');
}
?>
页面已经转换成utf-8モード了,可是直还是乱网