php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51919 $str[] unexpected result with multibyte character
Submitted: 2010-05-26 11:53 UTC Modified: 2010-05-26 11:55 UTC
From: msluis at sellvation dot nl Assigned:
Status: Not a bug Package: Strings related
PHP Version: Irrelevant OS: WinXP, Linux Debian
Private report: No CVE-ID: None
 [2010-05-26 11:53 UTC] msluis at sellvation dot nl
Description:
------------
When you access a multibyte character in an UTF-8 encoded string using array 
brackets [] it only returns the first byte instead of the full character.

WindowsXP SP3 PHP 5.3.0
WindowsXP SP3 PHP 5.3.2
Linux Debian  PHP 5.2.6-1+lenny8
Linux Debian  PHP 5.3.2-0.dotdeb.2

PHP Ini settings:
default_charset = "utf-8"
mbstring.internal_encoding = UTF-8
mbstring.func_overload = 7

http://us.php.net/manual/en/language.types.string.php#language.types.string.substr

Test script:
---------------
<?php

    $sStr = "André";

    var_dump($sStr);
    var_dump($sStr[4]);

?>

Expected result:
----------------
string(6) "André" 
string(1) "é"

Actual result:
--------------
string(6) "André" 
string(1) "�"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-26 11:55 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-05-26 11:55 UTC] johannes@php.net
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

PHP has no idea about"characters"just bytes.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 03:01:28 2024 UTC