Bug #37268 [Com]: basename() doesnt work with non-latin first letters of the file.

From: Date: Sat, 19 Mar 2016 09:29:44 +0000
Subject: Bug #37268 [Com]: basename() doesnt work with non-latin first letters of the file.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199938@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=37268&edit=1 ID: 37268 Comment by: lauri dot kentta at gmail dot com Reported by: spam dot bugs dot php dot net at vano dot org Summary: basename() doesnt work with non-latin first letters of the file. Status: Wont fix Type: Bug Package: Filesystem function related Operating System: Fedora Core 4 PHP Version: 5.1.2 Block user comment: N Private report: N New Comment: The default configuration of php-fpm clears the environment, which leads to this problem. Would it be possible to use UTF-8 or even default_charset or at least accept any 8-bit characters if the locale is unset or C? It's a bit strange that the current behaviour can't be controlled through php.ini but instead must be set with setlocale or environment variables. Previous Comments: ------------------------------------------------------------------------ [2015-03-12 08:39:54] mike@php.net You need to set the correct locale for stdlib/multibyte functions to work correctly; anyway, 3v4l.org apparently only has C/POSIX locale available: http://3v4l.org/M6jhm ------------------------------------------------------------------------ [2015-03-12 04:20:12] vovan-ve at yandex dot ru Are you sure this problem will be solved? http://3v4l.org/BWgUm ------------------------------------------------------------------------ [2010-07-31 23:21:11] daniel at mameso dot com a workaround: # workaround for splitting basename whith beginning utf8 multibyte char function mb_basename($filepath, $suffix = NULL) { $splited = preg_split ( '/\//', rtrim ( $filepath, '/ ' ) ); return substr ( basename ( 'X' . $splited [count ( $splited ) - 1], $suffix ), 1 ); } have fun, Daniel. PS: the problem does not exist under MAC OSX 10.6.x with ZendServerCE 5.0 & PHP5.3 ------------------------------------------------------------------------ [2006-05-02 00:55:17] judas dot iscariote at gmail dot com you have to wait PHP6, it will address this problems. ------------------------------------------------------------------------ [2006-05-01 23:56:42] spam dot bugs dot php dot net at vano dot org Description: ------------ If a file starts with a non-latin letter (cyrillic) and not with a non-letter character, basename will cut off the beginning of name untill a latin letter or a non-letter character found in the name. In my tests I was using Windows-1251 (CP1251) encoding and not UNICODE, so, the problem is in basename() function itself not in multi-byte charsets. P.S. if you have problem with text encoding of the example below, you can see a realtime example and test your own inputs there: http://examples.vano.org/basename.php Reproduce code: --------------- <?php echo basename("/test/blah/music/ðóññêèélatin.mp3"); ?> Expected result: ---------------- ðóññêèélatin.mp3 Actual result: -------------- latin.mp3 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=37268&edit=1

« previous php.bugs (#199938) next »