|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2019-04-17 13:33 UTC] mvachette at adequasys dot com
 Description: ------------ When using NumberFormatter on a PHP using ISO-8859-1 encoding, formatting a currency will result to a wrongly encoded thousands separator. (see sample script below) The obtained character could not be decoded in any format to obtain a regular "whitespace" - This issue is present only when using ISO-8859-1 encoding (sample scriupt works finie when using UTF-8) - This issue is not present in 7.2.9 (present at least since 7.2.15) ICU package versions: Internationalization support => enabled version => 1.1.0 ICU version => 63.1 ICU Data version => 63.1 ICU TZData version => 2018e ICU Unicode version => 11.0 Test script: --------------- $formatter = new \NumberFormatter( 'fr_fr', \NumberFormatter::CURRENCY ); var_dump($formatter->formatCurrency(1400, 'CHF')); //string(15) "1 400,00 CHF" PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 07:00:01 2025 UTC | 
Correction: I'm not getting U+802F, but rather U+202F with ICU 63.1. This is a NARROW NO-BREAK SPACE, which appears to be fine. Please post your output of: var_dump(bin2hex($formatter->formatCurrency(1400, 'CHF')));Thanks! This is also what I get. "e280af" represents a NARROW NO-BREAK SPACE, "c2a0" a NO-BREAK SPACE. Both are proper Unicode code points. While the NO-BREAK SPACE can be represented in ISO-8859-1, the NARROW NO-BREAK SPACE cannot. This is why iconv() raises a notice and fails. So to properly convert, do: iconv('UTF-8', 'ISO-8859-1//IGNORE', $formatter->formatCurrency(1400, 'CHF')) Or use mb_convert_encoding() which gives more flexibility than simply ignoring unsupported code points. Anyhow, this is not a bug.Thanks a lot for your investigations. The iconv with "IGNORE" flag works well. For information, I actually managed to keep the thousands separator by replacing the NARROW NO-BREAK SPACE by a regular whitespace before encoding conversion: $value = $formatter->formatCurrency(1400, 'CHF'); $valueWithoutNarrowNoBreakSpace = json_decode(str_replace('\u202f', ' ', json_encode($value))); var_dump(iconv('UTF-8', 'ISO-8859-1//IGNORE', $valueWithoutNarrowNoBreakSpace));