Home > Article > Backend Development > What to do if the php fread function is garbled
php fread function garbled solution: 1. Read the file directly through the fread function; 2. Pass the read content through the "iconv('gbk', 'utf-8', $data)" method Just transcode.
The operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer
What should I do if the php fread function is garbled?
Problem description: In
#php, the file is read directly through the fread function. If the file content encounters Chinese, garbled characters will appear. How to solve this problem? solve?
Solution:
Try transcoding the content after reading it out
iconv('gbk', 'utf-8', $data)
Related introduction:
iconv_get_encoding — Get the internal configuration variables of the iconv extension
iconv_mime_decode_headers — Decode multiple MIME header fields at once
iconv_mime_decode — Decode a MIME header field
iconv_mime_encode — Composes a MIME header field
iconv_set_encoding — Sets the current setting for character encoding conversion
iconv_strlen — Returns character count statistics for a string
iconv_strpos — Finds position of first occurrence of a needle within a haystack
iconv_strrpos — Finds the last occurrence of a needle within a haystack
iconv_substr — Intercept part of the string
iconv — Convert the string according to the required character encoding
ob_iconv_handler — Convert character encoding with output buffer handler
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What to do if the php fread function is garbled. For more information, please follow other related articles on the PHP Chinese website!