Bug #64424 [Csd]: number_format is not multibyte safe
| From: | rasmus@php.net | Date: | Thu, 14 Mar 2013 07:51:26 +0000 |
| Subject: | Bug #64424 [Csd]: number_format is not multibyte safe | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-177778@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64424&edit=1
ID: 64424
Updated by: rasmus@php.net
Reported by: mwalker at wikimedia dot org
Summary: number_format is not multibyte safe
Status: Closed
Type: Bug
Package: *Unicode Issues
Operating System: Ubuntu 12.04
PHP Version: 5.3.22
Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Note that it is easy enough to substitute single-char placeholders for now while
you are still stuck on 5.3:
$f = number_format((float)$val, $precision, 'X', 'Y');
$f = str_replace(array('X','Y'), array($decsep,$thousep), $f);
Not pretty, but effective.
Previous Comments:
------------------------------------------------------------------------
[2013-03-14 07:25:56] mwalker at wikimedia dot org
Awesome -- good to hear this has been fixed. Sadly I'm stuck on 5.3 for the
present time. Good tip on the intl extension -- haven't explored it in as much
depth as I should -- so thanks :)
------------------------------------------------------------------------
[2013-03-14 07:07:30] pajoye@php.net
Also I strongly recommend to move to Intl instead.
http://www.php.net/manual/en/numberformatter.format.php
------------------------------------------------------------------------
[2013-03-14 07:02:26] nikic@php.net
Support for this has already been added in PHP 5.4. See the changelog from http://php.net/number_format:
5.4.0 This function now supports multiple bytes in dec_point and thousands_sep. Only the first byte
of each separator was used in older versions.
------------------------------------------------------------------------
[2013-03-14 01:26:36] mwalker at wikimedia dot org
Description:
------------
I have a UTF-8 PHP file that initializes an array of characters depending on the
locale. Some of these are multibyte strings.
When using the number_format() function with $dec_point, or $thousands_sep set
with one of these multibyte entries the returned result contains only the first
byte of the string (which is only a partial code point.)
Test script:
---------------
$foo = "\xC2\xA0";
$result = number_format(1.23, $foo, $foo);
Expected result:
----------------
$result to contain "\x31\xC2\xA0\x32\x33"
Actual result:
--------------
$result seems to contain "\x31\xC2\x32\x33"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64424&edit=1