Ask why the MYSQL data called by PHP is garbled.

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.