I have one switch statement in my PHP code and it seems it doesn't execute case with the UTF-8 character even though value put to switch is UTF-8 character. It works with all other characters.
CO开发者_运维知识库DE:
echo $word[$i];
switch($word[$i]){
case "a": echo "aaaa"; break;
case "č": echo "aaaa"; break;
}
If the $word[$i] is "a" the code echoes "a" and "aaaa" if the $word[$i] is "č" the code echoes "č" but does not echo "aaaa". It simply ignores case with "č". I also tried case with single quotes.
If someone will someday need to use "str_split" for utf-8 strings here is working function:
function str_split_utf8 ($string, $split_length = 1)
{
$length = (int) $split_length;
$string = (string) $string;
if ($length < 1)
{
return false;
}
return preg_split("/(.{{$length}})/us", $string, -1,
PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
}
精彩评论