今天写程序时遇到一个小问题,pathinfo在处理中文文件名时出现的问题,如果中文在字首就出现获取的filename为空,英文在字首后面是中文的则能获取到。如下图:
于是自己写了个函数代替,代码如下:
复制代码 代码如下:
function path_info($filepath)
{
$path_parts = array();
$path_parts ['dirname'] = rtrim(substr($filepath, 0, strrpos($filepath, 'https://www.jb51.net/')),"https://www.jb51.net/")."https://www.jb51.net/";
$path_parts ['basename'] = ltrim(substr($filepath, strrpos($filepath, 'https://www.jb51.net/')),"https://www.jb51.net/");
$path_parts ['extension'] = substr(strrchr($filepath, '.'), 1);
$path_parts ['filename'] = ltrim(substr($path_parts ['basename'], 0, strrpos($path_parts ['basename'], '.')),"https://www.jb51.net/");
return $path_parts;
}
这样问题就解决了
您可能感兴趣的文章: