> >

Processing method of Chinese character displaying garbled when Re: PHP reads text files

time:17-06-28 forum:PHP tools and code
  The following code 3:

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.
  • 1
  • 2

prev:The solution of reading TXT Chinese chao... next:Distance between outer distance and oute...
post comments
Notice



Approved   South Korea's chief mother is popula...   The 3 year old was elected the young...   The Qilu Public Welfare Alliance has...   Beautiful and impressive: the nights...   Ji'nan Ying Bi Street School: specia...
rand      PHP filter special characters and SQ...   PHP gets all the pictures in the web...   PHP regularly gets the picture and d...   PHP completely filters HTML, JS, CSS...
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com