Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem of garbled characters after php is written into txt file

Shulou Source: shulou.com Published: 2022-06-03 12:49:30 11月15日 Update

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!

Tags: Files garbled characters questions content learning practicality deeper interest examples practicality practicality simplicity methods more friends examples websites channels UTF-8 Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Technology Xiaomi Huawei MySQL