Maison > Article > développement back-end > 采集天气编码有关问题
采集天气编码问题
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模式了,可是一直还是乱码