note 111076 added to language.types.string

From: Date: Fri, 11 Jan 2013 21:06:11 +0000
Subject: note 111076 added to language.types.string
Groups: php.notes 
Request: Send a blank email to php-notes+get-192945@lists.php.net to get a copy of this message
Altough the documentation says: Internally, PHP strings are byte arrays. As a result, accessing or modifying a string using array brackets is not multi-byte safe, and should only be done with strings that are in a single-byte encoding such as ISO-8859-1. I made this test file: <?php $string = "Hello World. 日本語と広東語が話せる"; $n = strlen($string); for($i = 0; $i < $n; $i++) { echo $string[$i]; } echo "\n"; ?> And saved it with UTF-8 encoding. I verified that the file was saved in UTF-8 encoding with Okteta (the KDE Hexadecimal editor) However when I ran it I got: Hello World. 日本語と広東語が話せる That is an unexpected behavior, specially because the Japanese characters are actually three bytes long. I tested it with PHP 5.4.6 and 5.3.2 with the same result. Something I cannot explain. ---- Server IP: 69.147.83.199 Probable Submitter: 190.158.209.174 ---- Manual Page -- http://php.net/manual/en/language.types.string.php Edit -- https://master.php.net/note/edit/111076 Del: integrated -- https://master.php.net/note/delete/111076/integrated Del: useless -- https://master.php.net/note/delete/111076/useless Del: bad code -- https://master.php.net/note/delete/111076/bad+code Del: spam -- https://master.php.net/note/delete/111076/spam Del: non-english -- https://master.php.net/note/delete/111076/non-english Del: in docs -- https://master.php.net/note/delete/111076/in+docs Del: other reasons-- https://master.php.net/note/delete/111076 Reject -- https://master.php.net/note/reject/111076 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#192945) next »