sfk sfk - 1 year ago 106
PHP Question

php get string each character

When I run the below code, I get

instead of first character which is

If i don't use any Turkish characters, I don't have any problem but when I use this characters which is
I'm having problems.

$str = "Şef";
echo $str[0];


for($i = 0; $i < strlen($str); $i++)
echo $str[$i] . '<br>';

How can resolve this problem? The header charset and HTML charset is utf-8 and my texteditor charset is utf-8 too.

Answer Source

I suggest you to use Multibyte String Functions http://docs.php.net/manual/en/ref.mbstring.php



$len = mb_strlen($str);

for($i = 0; $i < $len; $i++) {
    echo  mb_substr($str, $i, 1) . '<br>';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download