How to solve the problem of garbled characters after php is written into txt file
This article mainly explains "how to solve the problem of garbled characters after php is written into txt file", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn how to solve the problem of garbled characters after php is written into the txt file.
1. Create a sample PHP file.
2. Create "function file_utf8 ($filepath) {...}".
3. Save the txt file as "UTF-8".
Example
Function file_utf8 ($filepath) {$fancicontents = file_get_contents ($filepath); $encoding = mb_detect_encoding ($f_contents, array ('GB2312','GBK','UTF-16','UCS-2','UTF-8','BIG5','ASCII')); $content_u= ""; $handle=fopen ($filepath, "r"); if ($handle) {while (! feof ($handle)) {$buffer= fgets ($handle) If ($encoding! = false) {if (mb_detect_encoding ($buffer)! = 'UTF-8') {$buffer = iconv ($encoding,' UTF-8', $buffer);}} else {$buffer = mb_convert_encoding ($buffer, 'UTF-8','Unicode') } $content_u.=$buffer;} fclose ($handle); return $info=array ('status'= > 1 recording messagekeeper = > $content_u);} else {return $info=array (' status'= > 0memery messagebreaking = > 'failed to open the file') }} at this point, I believe you have a deeper understanding of "how to solve the problem of garbled characters after php is written into the txt file". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!