Bug #70591 [Com]: ord() no longer yields correct results consistently
Edit report at https://bugs.php.net/bug.php?id=70591&edit=1
ID: 70591
Comment by: slevy1 at pipeline dot com
Reported by: slevy1 at pipeline dot com
Summary: ord() no longer yields correct results consistently
Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: n/a
PHP Version: 7.0.0RC3
Block user comment: N
Private report: N
New Comment:
According to http://www.utf8-chartable.de/unicode-utf8-table.pl?start=9728,
when the black heart symbol (U+2665) is utf-8 encoded, the result is a multibyte string consisting
of 3 bytes whose hex values are e2 99 a5 which in decimal are 226 153
165. So, maybe the manual ought to document for mb_strcut() that one needs to specify the
parameter "iso-8859-1", if one wishes to provide that string to another function like
ord() since mb_strcut() originally was designed for that encoding. Or, should mb_strcut() be
reworked?
Previous Comments:
------------------------------------------------------------------------
[2015-09-27 00:37:14] requinix@php.net
https://wiki.php.net/rfc/default_encoding,
by the way
------------------------------------------------------------------------
[2015-09-27 00:36:02] requinix@php.net
The default character encoding, which your calls to mb_strcut() will be using, changed to be UTF-8
in PHP 5.6.
https://3v4l.org/YE6I9
------------------------------------------------------------------------
[2015-09-27 00:10:39] slevy1 at pipeline dot com
Description:
------------
I used ord() in combination with mb_strcut() to obtain the byte values of a multibyte char utf-8
encoded. This used to work in PHP 5.4.8 - 5.5.29. But in PHP5.6-PHP7.00rc3 it doesn't work
any more :(
Test script:
---------------
<?php
$str = "â¥"; // 3 byte values per above
var_dump( ord(mb_strcut($str, 0, 1) ));
var_dump( ord(mb_strcut($str, 1, 1) ));
var_dump( ord(mb_strcut($str, 2, 1) ));
see live code: https://3v4l.org/OoFus
Expected result:
----------------
I expected the var dumps to produce decimal results as follows:
226
153
165
Actual result:
--------------
0
0
0
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70591&edit=1
Thread (5 messages)