Processing method of Chinese character displaying garbled when Re: PHP reads text files
shows that the Chinese character is normal, indicating that the complete file can be read normally:
$files = file_get_contents ('d:/test.txt');
echo $files;
if in the first line of the script, the Chinese characters may appear to display chaotic codes. For specific reasons, please look at the little knowledge behind this article.
example 4:
if the text file is EXCEL file saved in TXT format, PHP may encounter some problems when reading. The problems I encountered were as follows:
example 5, using function file_get_contents read:
picture address http://album.sina.com.cn/pic/4c0b7a1bzx6GLBrUe4B65
picture address http://album.sina.com.cn/pic/4c0b7a1bzx6GLBAiLS7a7
, showing chaotic code. This shows that when using file_get_contents ('d:/test.txt'), when reading a complete text file, there is no problem in reading the Chinese character content and its display. When using fgets ($fh) to read one line of Chinese characters, the content and display of Chinese characters are confused.
this shows that the actual Terminator (i.e. carriage return) of each row in the text file is inconsistent with the assumption in fgets ($fh). The solution to
is:
the charset of the php.ini on the server side is set to UTF-8.
and then COPY all the contents of the text file, delete the text file, and then build a new file of the same name, the original text file content PASTE to the new file, storage this new text file, select the "UTF-8" format. Read the new file with script, and read the contents correctly. There will be no garbled code. Even if the code is displayed, the content of the Chinese characters read is correct.
under different operating system platforms, it means that the ending sign of each line is different, the specific reason is the little knowledge behind this article.