Bug #68303 [NEW]: str_split returns garbage when a certain UTF-8 character is passed
From: adrya dot stembridge at gmail dot com
Operating system: CentOS 6.5
PHP version: 5.6.2
Package: Output Control
Bug Type: Bug
Bug description:str_split returns garbage when a certain UTF-8 character is passed
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 bug report at https://bugs.php.net/bug.php?id=68303&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68303&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68303&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68303&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68303&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68303&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68303&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68303&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68303&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68303&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68303&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68303&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68303&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68303&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68303&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68303&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68303&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68303&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68303&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68303&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68303&r=mysqlcfg
Thread (3 messages)
- adrya dot stembridge at gmail dot com