php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64424 number_format is not multibyte safe
Submitted: 2013-03-14 01:26 UTC Modified: 2013-03-14 07:51 UTC
From: mwalker at wikimedia dot org Assigned: nikic (profile)
Status: Closed Package: *Unicode Issues
PHP Version: 5.3.22 OS: Ubuntu 12.04
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mwalker at wikimedia dot org
New email:
PHP Version: OS:

 

 [2013-03-14 01:26 UTC] 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"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-14 07:02 UTC] 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 07:02 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2013-03-14 07:07 UTC] 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:25 UTC] 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:51 UTC] rasmus@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 02:01:28 2024 UTC