1. 程式人生 > >PHP pathinfo 不支援中文 手動編寫解析路徑字串函式

PHP pathinfo 不支援中文 手動編寫解析路徑字串函式

pathinfo 在中文出現在首字的時候不支援用 自己的函式搞定:

如 "/home/ledmedia/TEST_BMP_1/視訊1.mp4"; 用pathinfo就會出問題

  1. function my_path_info($filepath)     
  2. {     
  3.     $path_parts = array();     
  4.     $path_parts ['dirname'] = rtrim(substr($filepath, 0, strrpos($filepath'/')),"/")."/";     
  5.     $path_parts ['basename'] = ltrim(substr
    ($filepathstrrpos($filepath'/')),"/");     
  6.     $path_parts ['extension'] = substr(strrchr($filepath'.'), 1);     
  7.     $path_parts ['filename'] = ltrim(substr($path_parts ['basename'], 0, strrpos($path_parts ['basename'], '.')),"/");     
  8.     return$path_parts;     
  9. }