Why is the MYSQL data in this PHP call garbled? -Php Tutorial

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

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.