今天写程序时遇到一个小问题,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;
}
这样问题就解决了