The solution on the Internet is to use iconv () for transcoding after capturing. After reading this, I realized something was wrong: one is that the iconv library is not necessarily compiled, the bigger problem is that encoding is related to stream conversion (if iconv is used, php actually turns the code twice: Stream-> UTF-8-> GB2312 ): isn't that too busy?
I carefully read the php documentation (I don't know how everyone writes code, but the documentation is very clear). The above section describes fopen () and file_get_contents () all mentioned "the default is UTF-8, but you can change the encoding with stream_default_encoding () or custom context attributes" (If unicode semantics are enabled, the default encoding of the read data is UTF-8. you can specify a different encoding by creating a custom context or by changing the default using stream_default_encoding ().). Use stream_default_encoding ('gb2312'); test: But the faint is, does this function not exist ?! It seems that php 6 is supported. However, there is no path to perfection, and "Custom context attributes" can be used.
After reading the document more carefully, we finally solved the problem:
Copy codeThe Code is as follows:
// Set the stream encoding format. This is a file. For network access, change file to http.
$ Opts = array ('file' => array ('encoding' => 'gb2312 '));
$ Ctxt = stream_context_create ($ opts );
File_get_contents (file name, FILE_TEXT, $ ctxt );