---
# System prepended metadata

title: 解決pathinfo()無法處理中文檔名問題
tags: [php]

---

---
title: 解決pathinfo()無法處理中文檔名問題
tags: php
---

撰寫函式替代原本的pathinfo()

```php=
function path_info($path)
{
    $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;
}
```