|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-10-09 22:54 UTC] i dot am dot brutto at gmail dot com
Description: ------------ --- From manual page: http://www.php.net/function.implode --- There is no any information aboout this strange behavior. =\ Detect this was difficult enough because do not expect problems in such simple core things. It's the same bug (https://bugs.php.net/bug.php?id=17815), but it dodn't fixed (as there marked). Test script: --------------- <?php $locale = 'ru_RU'; putenv("LANG=$locale" . '.UTF-8'); putenv("LANGUAGE=$locale" . '.UTF-8'); setlocale(LC_ALL, $locale . '.UTF-8'); // . '.UTF-8' $arr = array(12.12,12,23,21.44,67.88); print_r(implode(',', $arr)); Expected result: ---------------- there is no logic. other string functions not affected with this. and nowhere information about it. $arr = array(12.12,12,23,21.44,67.88); print_r(implode(' | ', $arr)); expected => 12.12 | 12 | 23 | 21.44 | 67.88 current => 12,12 | 12 | 23 | 21,44 | 67,88 (setlocale to ru_RU for example) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 11:00:02 2025 UTC |
Created a test for this: --TEST-- implode() function - Floats use locale settings --FILE-- <?php $locale = 'ru_RU'; putenv("LANG=$locale" . '.UTF-8'); putenv("LANGUAGE=$locale" . '.UTF-8'); setlocale(LC_ALL, $locale . '.UTF-8'); // . '.UTF-8' $arr = array(12.12,12,23,21.44,67.88); print_r(implode(',', $arr)); --EXPECT-- 12.12,12,23,21.44,67.88 From my end though, I couldn't seem to reproduce this. I tested this on a Windows build of 7.0.0-dev and on Ubuntu using their 5.5.9 package. 3v4l.org also shows that this works properly: http://3v4l.org/DpnLhFinally i realise what happens: all function return stings auto-format floats according to setllocale(). It means that event simple `echo $floatVar;` will be formatted as well. Ok. These logic clear. It would be good to add info about it in manual... But! If decimal sign are auto-formatted, expected that thousand sign will be also formatted (as in number_format()). Unfortunately that is not right in this php-version. Probably it was described somewhere else. IDN >>>> test: <?php $locale = 'ru_RU'; putenv("LANG=$locale" . '.UTF-8'); putenv("LANGUAGE=$locale" . '.UTF-8'); setlocale(LC_ALL, $locale . '.UTF-8'); $number = 12300.45; print_r(is_float($number)); // => true print_r($number); // => 12300,45 ][ Expected: 12 300,45 print_r('This is :' . $number); // => 'This is 12300,45' ][ Expected: 12 300,45 print_r(implode('::', array($number, 12.89))); //=> '12300,45::12,89' ][ Expected 12 300,45::12,89 die(); <<<<