Home  >  Article  >  Backend Development  >  Self-written function to solve the problem of Chinese language processing by pathinfo() function, _PHP tutorial

Self-written function to solve the problem of Chinese language processing by pathinfo() function, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:15:23931browse

Self-written function to solve the problem of pathinfo() function processing Chinese,

I encountered a small problem when writing a program today. Pathinfo has a problem when processing Chinese file names. If Chinese is at the beginning of the prefix, the obtained filename will be empty. If English is followed by Chinese at the beginning, it can be obtained. As shown below:

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

Copy code 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;
}

The problem is solved

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/904917.htmlTechArticleSelf-written function to solve the problem of Chinese language processing of pathinfo() function. Today I encountered a small problem when writing a program. Pathinfo is in Problems that arise when processing Chinese file names. If Chinese is at the beginning of the word, it will appear...
Statement:
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