|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-10-29 00:49 UTC] zgq0301 at gmail dot com
Description: ------------ function dirname can't return a string which the last character is chinese. Reproduce code: --------------- --- From manual page: function.dirname#Description --- code: $file="D:\Backup\我的文档\网站根目录d\cms"; echo dirname($file); then it print D:\Backup; but when I add a english character: $file="D:\Backup\我的文档\网站根目录d\cms"; echo dirname($file); it can well done. Expected result: ---------------- code: $file="D:\Backup\我的文档\网站根目录d\cms"; echo dirname($file); then it print D:\Backup; but when I add a english character: $file="D:\Backup\我的文档\网站根目录d\cms"; echo dirname($file); it can well done. Actual result: -------------- code: $file="D:\Backup\我的文档\网站根目录d\cms"; echo dirname($file); then it print D:\Backup; but when I add a english character: $file="D:\Backup\我的文档\网站根目录d\cms"; echo dirname($file); it can well done. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 10:00:01 2025 UTC |
It seems to me that this is not a bug, but rather a character encoding resp. locale related issue. As the documentation of dirname()[1] states: | dirname() is locale aware, so for it to see the correct | directory name with multibyte character paths, the matching | locale must be set using the setlocale() function. FWIW: Assuming UTF-8, the test script could be written: $file = "D:\\Backup\\\xE6\x88\x91\xE7\x9A\x84\xE6\x96\x87" . "\xE6\xA1\xA3\\\xE7\xBD\x91\xE7\xAB\x99\xE6\xA0\xB9" . "\xE7\x9B\xAE\xE5\xBD\x95\cms"; echo dirname($file); [1] <http://php.net/manual/en/function.dirname.php#refsect1-function.dirname-notes>