Self-compiled functions solve the problem of pathinfo () function processing in Chinese. _ PHP Tutorial

Source: Internet
Author: User
The self-compiled function solves the problem that the pathinfo () function can process Chinese characters ,. The self-compiled function solves the problem of pathinfo () function processing Chinese characters. today, when writing a program, there is a small problem, if the Chinese character is at the beginning of the word, the self-compiled function will solve the problem of the pathinfo () function processing the Chinese character,

Today, I encountered a small problem when writing a program. pathinfo encountered a problem when processing the Chinese file name. if the Chinese character is at the beginning, the obtained filename is blank, if the English is followed by a Chinese character, you can obtain it. For example:

So I wrote a function instead. the code is as follows:

The code is as follows:


Function path_info ($ filepath)
{
$ Path_parts = array ();
$ Path_parts ['dirname'] = rtrim (substr ($ filepath, 0, strrpos ($ filepath ,'/')),"/")."/";
$ Path_parts ['basename'] = ltrim (substr ($ filepath, strrpos ($ filepath ,'/')),"/");
$ Path_parts ['extension'] = substr (strrchr ($ filepath, '.'), 1 );
$ Path_parts ['filename'] = ltrim (substr ($ path_parts ['basename'], 0, strrpos ($ path_parts ['basename'], '. ')),"/");
Return $ path_parts;
}

This solves the problem.




When writing a program today, pathinfo encountered a problem in processing the Chinese file name. if the Chinese character is at the beginning of the word...

Related Article

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.