Why is the MYSQL data in this PHP call garbled? Function & nbsp; writeStatistic ($ SQL, $ txt_name) {$ filename. $ txt_name; change the file path if & nbsp; (file_exists ($ filename) & nbsp; {$ fpfopen ($ filename, a + );} else could you tell me why MYSQL data called by PHP is garbled?
Function writeStatistic ($ SQL, $ txt_name ){
$ Filename = "". $ txt_name; // modify the file path.
If (file_exists ($ filename )){
$ Fp = fopen ($ filename, "a + ");
} Else {
$ Fp = fopen ($ filename, "w + ");
}
$ Text = $ SQL. "\ r \ n ";
Fwrite ($ fp, $ text );
Fclose ($ fp );
}
/**
* Write character set setting handle to a specified file
*
* Parameter: string $ txt_name: specifies the file name.
* Return value: void
* Scope: public
*/
Function writeStatistic_set_name ($ txt_name ){
$ Set_name ="
";
// Convert to UTF-8 encoding
$ Filename = "". $ txt_name; // modify the file path.
If (file_exists ($ filename )){
Unlink ($ filename );
$ Fp = fopen ($ filename, "a + ");
} Else {
$ Fp = fopen ($ filename, "w + ");
}
$ Text = $ set_name. "\ r \ n ";
Fwrite ($ fp, $ text );
Fclose ($ fp );
}
$ NowDate = date ("Y-m-d ");
$ Txt_name = 'sitemap. XML ';
WriteStatistic_set_name ($ txt_name );
$ SQL = "select * from jieqi_article_article ORDER BY lastupdate DESC ";
$ Db-> query ($ SQL );
For ($ I = 1; $ I <= $ db-> num_rows (); $ I ++ ){
$ Db-> next_record ();
$ Siteid = $ db-> f (siteid );
$ Haha = _;
$ Articleid = $ db-> f (articleid );
$ Newname = $ db-> f (articlename );
$ Newid = $ db-> f (lastchapterid );
$ NowDate = $ db-> f (lastupdate );
$ NowDate = date ("Y-m-d H: m: s", $ nowDate );
$ Url ="
Http://www.1.org/html/?articleid/?newid.html
$ NowDate
Always
1.0
$ Newname
";
// Convert to UTF-8 encoding
$ Url = utf8_encode ($ url );
WriteStatistic ($ url, $ txt_name );
}
$ Db-> free ();
$ Over ='
';
WriteStatistic ($ over, $ txt_name );
Print "Google Sitemap generation ends!
Click here to view ";
Exit;
?>
The generated result is as follows ..
How can I correctly call the Chinese text?
------ Solution --------------------
You used the wrong function!
$ Url = utf8_encode ($ url );
To change
$ Url = iconv (; gbk ', 'utf-8', $ url );
Of course, the data encoding in $ url must be
In fact, you set the $ db character set to utf8 without transcoding.