How to iterate UTF-8 string in PHP?

Arexwheneouro

New Member
How to iterate a UTF-8 string character by character using indexing?When you access a UTF-8 string with the bracket operator \[code\]$str[0]\[/code\] the utf-encoded character consists of 2 or more elements. For example:\[code\]$str = "K?t";$str[0] = "K";$str[1] = "?";$str[2] = "?";$str[3] = "t";\[/code\]but I would like to have:\[code\]$str[0] = "K";$str[1] = "?";$str[2] = "t";\[/code\]It is possible with \[code\]mb_substr\[/code\] but this is extremely slow, ie.\[code\]mb_substr($str, 0, 1) = "K"mb_substr($str, 1, 1) = "?"mb_substr($str, 2, 1) = "t"\[/code\]Is there another way to interate the string character by character without using \[code\]mb_substr\[/code\]?
 
Back
Top