Home >Backend Development >PHP Tutorial >PHP solves database garbled problem_PHP tutorial
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);