Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The solution of garbled codes transmitted from Chinese to background in php

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you the "php Chinese to the background garbled solution", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn the "php Chinese to the background garbled solution" this article.

Php Chinese to the background garbled solutions: 1, the use of "iconv ('UTF-8',' GB2312//IGNORE', $targetFile);"; 2, the use of "move_uploaded_file ($tempFile, $targetFile);

This article operating environment: Windows7 system, PHP7.1 version, Dell G3 computer.

Solution to the problem of garbled Chinese characters stored at the background of uploading php files:

Description of background processing for uploading php files:

After the user uploads the file (I use uploadify2.3 at the front end), I want to save it according to its original file name (sometimes in Chinese). Only using php's move_uploaded_file command will cause garbled (I am ubuntu's server). It is necessary to use icotargetFile=iconv first ('UTF − 8 minutes magnetism GB2312); without IGNORE, iconv will fail to convert the character-(horizontal bar), and then automatically truncate it. For example:

Iconv ('UTF-8',' GB2312//IGNORE', "blog-yet"); / / output "blog yet" iconv ('UTF-8',' GB2312//IGNORE', "blog-yet"); / / output "blog"

So the correct storage method is:

$targetFile = iconv ('UTF-8',' GB2312//IGNORE', $targetFile); / / UTF8 to GB2312move_uploaded_file ($tempFile, $targetFile); / / the server temporarily places the file on $tempFile

Because transcoding loses characters, we need to save the new file name. To determine which characters are missing, I used trick that converts back and forth like this:

$targetFile = iconv ('GB2312',' UTF-8//IGNORE', $targetFile)

Background processing for downloading php files:

When to use GB2312 and when to UTF8 is important.

In addition, ob_clean () and flush () are the key to whether the downloaded file is garbled.

The following is the file upload backend file I used with uploadify 2.3.For reference only:

The above is all the contents of this article entitled "the solution to garbled codes from php Chinese to the background". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 250

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report