Home > Backend Development > PHP Problem > Can't Chinese characters be added to the php file name?

Can't Chinese characters be added to the php file name?

(*-*)浩
Release: 2023-02-26 21:20:01
Original
2334 people have browsed it

It is not recommended to use Chinese file names!

Because Chinese will be sent in URL encoding, although it will be decoded when it is sent to the server, if it is inconsistent with your encoding, it will not be decoded.

Can't Chinese characters be added to the php file name?

Simply put, the Chinese in the URL will be encoded in UTF-8 by default in common browsers. Send to server! In the Chinese windows environment server, when decoding the URL, gb2312 encoding is used for decoding, which results in the inability to get the original Chinese text you entered in the address bar!

So it will prompt that the file name cannot be found.

If you must use Chinese, the solution is limited to your local browsing solution

In the browser, open the "Internet Options" menu, select "Advanced", and then Find "Send UTF-8 URL" and remove the previous hook. Then confirm.

Restart the browser. In this way, the Chinese in the address bar will be sent in gb2312 encoding by default, so that the server can correctly find the file with the Chinese file name

The chartset of the previous web page used utf-8, and the file Also use utf-8, and then use fopen() to create a file with a Chinese file name. The problem comes out, the file name is garbled!

I checked a lot of documents and tried many methods but couldn't solve it. I was originally thinking of using other methods to bypass this problem, but suddenly it occurred to my mind that the default text encoding of Windows is ansi, and then I searched again and confirmed it. In order to understand this, my web page should also be ansi encoded so that the created file name will not be garbled.

Then I started to verify. I saved the webpages with ansi and removed the chartset statement. It was ok, but the content of the webpage became garbled. Later I remembered that this webpage also included other webpages, so I changed the include The webpage has also been changed to ansi to save, haha ​​everything is ok

Programming is really a job that relies on accumulation. If I had never seen that the default encoding of Windows is ansi, then this problem will not be solved in a long time

ps: < meta content ="text/html; charset=utf-8" http -equiv ="Content-type" > This meta tag must be placed in It only worked before

Then I thought of a better solution. The webpage is still encoded and saved in utf-8. It is just a matter of encoding the file name parameter in fopen() separately. PHP has iconv() is a program that changes the encoding. It converts utf-8 to gb2312 to avoid garbled Chinese file names.

The above is the detailed content of Can't Chinese characters be added to the php file name?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template