The solution of reading TXT Chinese chaotic code by PHP
you need to read a TXT file using PHP because of business requirements, but there is a nauseous code problem on the issue of design to Chinese; First look at the encoding format of TXT: ANSI, Unicode, Unicode Big Endian, UTF-8
1. Code format, but it can be used instead of ANSI and UTF-8 format;
2, so for this problem, a special conversion is made:
[code]
$str = mb_convert_encoding ($str,'UTF-8','Unicode'); Break.
complete code as follows:
[code]
if ($fname = $_FILES.#91;'nickname'.#93;.#91; > / / / > $= = = = = $= $ Contents, array ('GB2312','GBK','UTF-16','UCS-2','UTF-8','BIG5','ASCII');
; / / / / / > $num;
$str = trim (fgets ($fp));
if ($encoding! = false). Text = $str;
}
}
else {
$str = > = $str;
}
}
}
while (! (feof ($fp)). $str = iconv ($encoding,'UTF-8', $str);
if ($str! =.Quot;.Quot; and). $str = mb_convert_encoding ($str,'UTF-8','Unicode');
if ($str! =.Quot;.Quot; and). Ode]