PHP Chinese garbled, Winodws and Linux under different processing questions?

Source: Internet
Author: User
Tags learn php hosting web hosting
I used wamp myself to build a local site to learn PHP, the system is WINDOWS8, Web page is:
Coding
However, in the processing of Chinese directories and filenames garbled, search on the internet said to be used
$dir =iconv (' UTF-8 ', ' GB2312 ', $dir); Decode the directory in Chinese and then do it again, then use
$dir =iconv (' GB2312 ', ' UTF-8 ', $dir); The anti-coding is displayed.
This method is also feasible.
However, I did not expect to upload the page to the purchase of the WEB HOSTING server, there will be garbled,
Without decoding and anti-decoding operation will not appear garbled, WEB HOSTING is LINUX under the CPANEL,
I really can't figure out why this difference occurs.
Younger brother Beginner PHP, have the warrior for me to dispel the reason that this kind of problem arises?
Or is my site on my local machine not configured properly?


Reply to discussion (solution)

In fact, it is not recommended to use the Chinese directory path.
Try changing the GB2312 to GBK.

Operating system Character Set
Winodws GBK
Linux UTF-8

When the Web page character set is the same as the operating system character set, the file name does not need transcoding

If I develop a generic template for PHP, what to do, but also to determine the system set?

Yes, since it is universal, it is necessary to respond to different environments accordingly.
Can't leave the problem to the user

For example, your Chinese file name problem, it should not be simple $dir =iconv (' UTF-8 ', ' GB2312 ', $dir);
And you can do this:
In the configuration file, write to
Define (' App_charset ', ' UTF-8 ');
Define (' Os_charset ', substr (php_os, 0, 3) = = ' WIN '? ' GBK ': ' UTF-8 ');

This $dir =iconv (' UTF-8 ', ' GB2312 ', $dir);
Writing $dir =iconv (' App_charset, Os_charset, $dir);
It's universal.
can also be further
function lang (& $str) {
return $str = Iconv (' App_charset, Os_charset, $STR);
}
In the program
Lang ($dir);
$path = lang ($dir);
All can

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.