Collect Weather coding problems
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 ');
}
?>
The page has been converted into utf-8 mode, but it's still garbled.
Share to: more
------Solution--------------------
Put your code test, no problem, there is no garbled! You see your program file itself has not been saved into the UTF8 format!
------Solution--------------------
Does your code work correctly?
Please give the correct test parameters