Processing method of Chinese characters displaying random code when PHP reads text files

time:17-06-28 forum:PHP tools and code
  http://blog.sina.com.cn/s/blog_4c0b7a1b0101gm1l.html

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

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



approved   26 mountain parks all over Ji'nan   The young man insisted on 10 years' ...   Do you remember those "made in Ji'na...   Ji'nan's Daming Lake scenic area is ...   Ji'nan free Scenic Area
rand   Using iconv to transform UTF-8 Chine...   The strftime () function converts mo...   PHP string intercepting function   The interrotation of time stamp func...   PHP code for different cities from I...
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