Hongmu Notes
Home Summary of pitfalls What should I do if the output file name displayed in Windows shows garbled characters?
Summary of pitfalls

What should I do if the output file name displayed in Windows shows garbled characters?

What should I do if the output file name displayed in Windows shows garbled characters?

My code:

$filesss = glob('./pic/*.jpg');
print_r($filesss);

When running the program on a Windows environment, the output file name displays as garbled text.

Invalid character display reason:

On Windows, PHP uses the system's default encoding by default when processing file names; this can cause file names containing Chinese characters or other non-ASCII characters to be displayed as garbled text during output.

Solution:

Use iconv() The function converts the file name into an appropriate encoding before outputting it.

Final code:

$filesss = glob('./pic/*.jpg');

// 遍历文件数组,并使用 iconv 函数转换编码
foreach ($filesss as $file) {
    // 将文件名从系统默认编码转换为 UTF-8
    $file_utf8 = iconv("CP936", "UTF-8", $file); // CP936 是 Windows 下的默认中文编码

    // 输出转换后的文件名
    echo $file_utf8 . "\n";
}

iconv("CP936", "UTF-8", $file)It converts the Windows default Chinese character encoding (CP936, also known as GBK) to UTF-8 encoding, ensuring that the file names are displayed correctly.

If the original encoding of the file name is not CP936 but another encoding (e.g., UTF-8), you should adjust it accordingly based on the actual situation. iconv() Parameters in a function.

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

Browser caching increases the speed of secondary visits to your website

Browser caching increases the speed of secondary visits to your website Summary of pitfalls

Use browser caching of official words: If users will visit your website multiple times, browser caching of static resources can save users time. Cache headers should be applied to all cacheable static resources, not just to a small subset of static resources (for example, images). Cacheable resources include JS and CSS files, image files, and other binary object files (media files, PDF files, etc.). Normally, HTML doesn’t…
👁 202

Recommended reading

Responsive Metal Craft Pendant Website Template 0635

Responsive Metal Craft Pendant Website Template 0635 Practical Collection Yiyou template

This EyouCMS responsive template is ideal for the metal crafts and accessories industry. Its sophisticated and artistic design perfectly showcases metal craft products, decorative accessories, creative designs, and brand stories. It helps craft brands showcase their products online and attract both collectors and gift-giving customers. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS...
👁 61
Plastic running track & plastic flooring website template – 0016

Plastic running track & plastic flooring website template – 0016 Practical Collection Yiyou template

This EyouCMS template is ideal for companies specializing in synthetic running tracks and synthetic flooring solutions. Its fresh, sporty design effectively showcases running track and flooring products, construction case studies, and technical solutions. It enables sports facility construction firms to demonstrate their engineering expertise online and attract clients such as schools and sports venues. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Common Questions Regarding EyouCMS Installation...
👁 40
(Adaptive mobile version) Simplified/Traditional Chinese bilingual responsive HTML5 universal financial capital consulting website single-page PbootCMS template – 0594

(Adaptive mobile version) Simplified/Traditional Chinese bilingual responsive HTML5 universal financial capital consulting website single-page PbootCMS template – 0594 Practical Collection pbootcms Template

A responsive, bilingual (Simplified and Traditional Chinese) universal financial capital consulting brochure template built with PbootCMS, compatible with both PC and WAP devices. Featuring a professional marketing design, this template is ideal for financial consulting and capital services firms seeking to enhance their online presence and acquire new customers. The bilingual support facilitates market expansion across the Taiwan Strait. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn...
👁 44
Responsive Mechanical Diaphragm Valve Website Template 0636

Responsive Mechanical Diaphragm Valve Website Template 0636 Practical Collection Yiyou template

An eYouCMS responsive website template designed for the mechanical valve and diaphragm valve industries. Its professional industrial design style is ideal for showcasing valve products, technical specifications, industrial applications, and engineering case studies. This template helps valve manufacturing companies showcase their products online and attract customers from the chemical and pharmaceutical sectors. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Common Installation Questions for eYouCMS...
👁 40
High-end whole-house solid wood custom furniture website template – 0017

High-end whole-house solid wood custom furniture website template – 0017 Practical Collection Yiyou template

An eYouCMS website template designed for high-end whole-house solid wood custom furniture businesses. Its luxurious and sophisticated design effectively showcases custom solid wood furniture, whole-house renovation projects, and design concepts, helping premium furniture customization brands attract high-quality customers online. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Questions for eYouCMS | eYouCMS...
👁 45