Home >Backend Development >PHP Problem >What to do if the php fread function is garbled

What to do if the php fread function is garbled

藏色散人
藏色散人Original
2021-09-18 09:54:402709browse

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.

What to do if the php fread function is garbled

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn