note 111076 deleted from language.types.string by aharvey

From: Date: Mon, 14 Jan 2013 01:47:42 +0000
Subject: note 111076 deleted from language.types.string by aharvey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193020@lists.php.net to get a copy of this message
Note Submitter: sergio dot bobillier at gmail dot com ---- 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.

« previous php.notes (#193020) next »