采集天气编码有关问题
程序员文章站
2024-01-13 15:48:40
...
采集天气编码问题
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);
}
function 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'];
return $id;
}
function connect_sql(){
$con = mysql_connect('localhost','root','123456') or die('mysql error :'.mysql_error());
mysql_select_db('test');
mysql_query('set names utf8');
}
?>
页面已经转换成utf-8模式了,可是一直还是乱码
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);
}
function 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'];
return $id;
}
function connect_sql(){
$con = mysql_connect('localhost','root','123456') or die('mysql error :'.mysql_error());
mysql_select_db('test');
mysql_query('set names utf8');
}
?>
页面已经转换成utf-8模式了,可是一直还是乱码
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
- 最新文章
- 热门排行
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论