Why is the MYSQL data in this PHP call garbled?
Function writeStatistic ($ SQL, $ txt_name) {$ filename = "". $ txt_name; // change 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);}/*** set the handle to the character set written to the specified file ** parameter: string $ txt_name: specify the file name * return: void * scope: public */function writeStatistic_set_name ($ txt_name) {$ set_name ="
"; // Convert to UTF-8 encoding $ filename = "". $ txt_name; // change 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 encoded $ 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?
Reply to discussion (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.