Processing method of Chinese characters displaying random code when PHP reads text files
it is used PHP to read the content source in the txt file, see the following scripting program.
1:
Photo address http://album.sina.com.cn/pic/4c0b7a1bzx6GLARDWeDcb
although the content of "communication directory.Txt" is Chinese, the read should be Chinese, but the result of the read is a heap of random codes!
how to deal with the garbled code?
to solve the problem thoroughly, it is necessary to make clear the way that the text is encoded in the computer code format and the various operating systems handle the lines of the text file in the text file (see the small knowledge behind this article, and the reference material).
now summed up the train of thought, no more than the following:
1. though the display is random code, but the content of the read Chinese is correct, just display the chaotic code. The solution to
is to declare the encoding format of characters in the web file.Html, such as:
http://album.sina.com.cn/pic/001oldd9zy6GMLhUapTdd
, but the above charset=utf-8 may cause Chinese characters to be displayed as chaotic codes, and can be changed to charset=GB2312 for insurance.
if you simply write the PHP script and don't know the format of the page code that this script runs, you can also add a line of header (.Quot; Content-Type: text/html; charset=GB2312.quot;) to the PHP script (program) for insurance. This line is the header information and must be placed at the beginning of the PHP script to specify the display of the text. The example is as follows:
picture address http://album.sina.com.cn/pic/4c0b7a1bzx6GLB6fX6Ua0
2., although the display is random code, but the content of the read Chinese characters is also random code.