When using PHP\'s pathinfo() function on a filename known to be UTF-8, it does not return the correct value, unless there are \'normal\' characters in front of
When process ansi characters, the function pathinfo do correctly.
Base this note, we will convert (encoding) input to ansi charaters and then still use function pathinfo to keep its whole things.
Finally, we will convert (decoding) output values to original format.
And demo as bellowing.
function _pathinfo($path, $options = null)
{
$path = urlencode($path);
$parts = null === $options ? pathinfo($path) : pathinfo($path, $options);
foreach ($parts as $field => $value) {
$parts[$field] = urldecode($value);
}
return $parts;
}
// calling
_pathinfo('すtest.jpg');
_pathinfo('すtest.jpg', PATHINFO_EXTENSION);