"Go" php basename function does not support the resolution of Chinese names

Source: Internet
Author: User
Tags vars

Today, when using the basename function to get the file name, it is found that if the Chinese file name returns only the empty name of the suffix (for example:. pdf)
String basename (String path [, string suffix])
Description
Give a string containing a full path to a file, this function returns the base file name. If the file name ends in suffix, then this part will be removed as well.
Method One: Follow the Web site to find the argument is that this function depends on the locale, if the multibyte name returned as null can be set by the setlocale function as follows

View Plainprint?
    1. <?php
    2. SetLocale (Lc_all, ' ZH_CN.  GBK ');
    3. Or any of the other locales that can handle multibyte characters.
    4. ?>


It is best to modify the server's regional settings to solve the overall!

Method Two: Php comes with the basename function does not support Chinese, the following method is the simplest implementation.

View Plainprint?
    1. function Get_basename ($filename) {
    2. return preg_replace ('/^.+[\\\\\\/]/', ', $filename);
    3. }

"Go" php basename function does not support the resolution of Chinese names

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.