Home  >  Article  >  Backend Development  >  PHP solves database garbled problem_PHP tutorial

PHP solves database garbled problem_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:52:17674browse

If the database uses UTF-8, what encoding do you use for the text?

Use mb_convert_encoding or iconv to convert the encoding. The two codes must be consistent so that there will be no garbled characters. There is also the database connection. If you have added set names, all connections should be added in this way. Otherwise, garbled characters will be displayed.

The following example questions will have problems if the encoding is not converted.

$fileName = "qtgz/qtgongzi.txt";
$ FCONTENT = FILE ($ FILENAME);
​ ​ ​ ​ ​ //Pay the value of the current element to $a_content list and pay the value of the array element to some variables
FOREACH ($ FCONTENT As $ A_Content) {
               list($QT_sfz,$QT_xm,$QT_bz,$QT_je) = explode( ",",$a_content);
                  if($QT_sfz!= "" and $QT_xm !="" and $QT_bz !="" and $QT_je !=""){
                    echo $QT_xm;
​ ​ ​ ​ ​ //Get the time and insert it into the database
                 $QT_sj = date("Ym");
$query = "insert into qita(QT_sfz,QT_xm,QT_bz ,QT_je,QT_beizhu,QT_sj) values('$QT_sfz','$QT_xm','$QT_bz','$QT_je','$QT_beizhu','$QT_sj ')";
                   //echo $query;
                                     $rst = $aa->excu($query);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632490.htmlTechArticleIf the database uses UTF-8, what encoding do you use for the text? Use mb_convert_encoding or iconv to convert the encoding. The two codes must be consistent so that there will be no garbled characters. And...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn