今天寫程序時遇到一個小問題,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;
}
這樣問題就解決了