Home >Backend Development >PHP Tutorial > 采集天气编码有关问题

采集天气编码有关问题

WBOY
WBOYOriginal
2016-06-13 12:31:09802browse

采集天气编码问题

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模式了,可是一直还是乱码

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article: 求课程 Next article: 为啥mysql_fetch_array没有执行