Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-13 09:22:28
Original
895 people have browsed it

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

今天写程序时遇到一个小问题,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;  

这样问题就解决了

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!