Home >Backend Development >PHP Tutorial >自编函数解决pathinfo()函数处理中文问题_PHP

自编函数解决pathinfo()函数处理中文问题_PHP

WBOY
WBOYOriginal
2016-05-31 19:28:41774browse

今天写程序时遇到一个小问题,pathinfo在处理中文文件名时出现的问题,如果中文在字首就出现获取的filename为空,英文在字首后面是中文的则能获取到。如下图:

于是自己写了个函数代替,代码如下:

代码如下:


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;  

这样问题就解决了

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