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...