Bug #68303 [Opn->Nab]: str_split returns garbage when a certain UTF-8 character is passed
| From: | aharvey@php.net | Date: | Fri, 24 Oct 2014 20:18:26 +0000 |
| Subject: | Bug #68303 [Opn->Nab]: str_split returns garbage when a certain UTF-8 character is passed | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-188297@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68303&edit=1
ID: 68303
Updated by: aharvey@php.net
Reported by: adrya dot stembridge at gmail dot com
Summary: str_split returns garbage when a certain UTF-8
character is passed
-Status: Open
+Status: Not a bug
Type: Bug
Package: Output Control
Operating System: CentOS 6.5
PHP Version: 5.6.2
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
str_split() isn't multibyte aware; http://php.net/str_split#107658 describes a method of
using preg_split() to implement a function similar to str_split() that is.
Previous Comments:
------------------------------------------------------------------------
[2014-10-24 20:07:08] adrya dot stembridge at gmail dot com
Description:
------------
I am attempting to break up a string of initials in order to add periods after each letter. Ex, AMA
becomes A.M.A. I'm using str_split to generate an array, which I then glue together with
periods.
The problem is when I have a certain UTF8 character in the string: "ÅZ". str_split
appears to not like the UTF8 encoding of the first letter. I've added some debug output in the
code snippet below.
Test script:
---------------
$str_initials = "ÅZ";
echo "<p><b>\$str_initials</b> $str_initials<p>";
$arr_initials = str_split($str_initials);
print_r($arr_initials);
echo "<p>";
foreach ($arr_initials as $initial)
{
echo "<b>\$initial</b> $initial<br>";
$arr_ni[] = $initial . '.';
}
$str_initials = implode($arr_ni);
echo "<p><b>\$str_initials</b> $str_initials";
Expected result:
----------------
ÅZ becomes Å.Z.
Actual result:
--------------
ÅZ becomes �.�.Z.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68303&edit=1