Bug #81584 [Asn->Ana]: mb_strwidth() returns incorrect value
| From: | alexdowad@php.net | Date: | Mon, 01 Nov 2021 19:32:04 +0000 |
| Subject: | Bug #81584 [Asn->Ana]: mb_strwidth() returns incorrect value | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-237489@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81584&edit=1
ID: 81584
Updated by: alexdowad@php.net
Reported by: azjezz at protonmail dot com
Summary: mb_strwidth() returns incorrect value
-Status: Assigned
+Status: Analyzed
Type: Bug
Package: mbstring related
Operating System: N/A
PHP Version: 8.1.0RC5
Assigned To: alexdowad
Block user comment: N
Private report: N
New Comment:
Azjezz, thanks for the report!
First of all, the Unicode Consortium maintains the standard on which Unicode characters are
considered 'halfwidth' and which are 'fullwidth'. See: http://www.unicode.org/reports/tr11/
If you download all the data tables for the Unicode standard from unicode.org, you can see the raw
data on character width in the file EastAsianWidth.txt.
In the first example you kindly provided, the coffee cup emoji are U+2615. The latest version of the
Unicode standard indicates these are 'fullwidth' characters. Plus 2 for the spaces, the
output of 8 is therefore correct.
Likewise, the gold, silver, and bronze medal emoji are all fullwidth. So 6 is the correct output.
And as for the horoscope symbols... yep, they are also fullwidth.
In summary, the latest version of PHP complies with the latest Unicode standard, and the previous
version of PHP did not. Now, I would like to find out... is this causing a problem for you? Is there
some reason why you preferred the old Unicode standard to the new one? Looking forward to your
feedback.
Previous Comments:
------------------------------------------------------------------------
[2021-11-01 17:44:12] nikic@php.net
Possibly due to https://github.com/php/php-src/commit/d8c785b894e1a4ed9793d71cad02330cb0034faa?
------------------------------------------------------------------------
[2021-11-01 17:19:24] azjezz at protonmail dot com
test script: https://3v4l.org/X6DWb
------------------------------------------------------------------------
[2021-11-01 17:17:33] azjezz at protonmail dot com
Description:
------------
The "width" or a string containing emojis has changed between PHP <= 8.0 and 8.1.
Test script:
---------------
var_dump(
mb_strwidth('â â â'),
mb_strwidth('????????????'),
mb_strwidth('ââââââââââââ'),
);
Expected result:
----------------
int(5)
int(3)
int(12)
Actual result:
--------------
int(8)
int(6)
int(24)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81584&edit=1