數據庫是用UTF-8的話,你那個文本是使用什麼編碼呀?
用mb_convert_encoding或iconv來轉換一下編碼。兩個編碼要一致才不會出現亂碼的。還有就是數據庫連接方面,如果你有加了set names應該是全部的連接都要那樣去加,要不然,會顯示亂碼的。
下在的例題如果不進行編碼轉換就會有問題.
$fileName = "qtgz/qtgongzi.txt";
$fContent = file($fileName);
//將當前元素的值付給$a_content list把數組元素的值付給一些變量
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;
//取得時間插入到數據庫中
$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);