Collection weather encoding & lt; meta & nbsp; http-equivContent-Type & nbsp; contenttexthtml; & nbsp; charsetutf-8 & nbsp; & gt; & lt ;? Phpset_time_limit (0); connect_ SQL (); $ names & nbsp; trim ($ _ GET [Weather collection encoding problem
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', '000000') or die ('MySQL error: '. mysql_error ());
Mysql_select_db ('test ');
Mysql_query ('set names utf8 ');
}
?>
The page has been converted to UTF-8 mode, but it is still garbled
Share: More
------ Solution --------------------
Test your code. No problem, no garbled code! Check whether your program file is saved in utf8 format!
------ Solution --------------------
Can your code run correctly?
Provide correct test parameters