Reputation: 17
Everything is set to UTF-8 (file encoding, MySQL [however I don't use it], Apache, meta, mbstring etc...) but check this out:
$s="áéőúöüóűí";
echo $s; //works perfectly
echo $s[0] // doesn't work. Prints out a single '?'.
I have tried almost everything. Any ideas? Thanks in advance!
Upvotes: 0
Views: 272
Reputation: 1301
you have to make some changes in database go to the the table structure
you can find a column "Collation"
which column you want to change click edit on right side menu
the default Collation is - 'latin1_general_ci' change it to 'utf8_general_ci'
Upvotes: -1
Reputation: 1536
And if you define $s[0]="á", does it work ? I believe that when encoded in UTF-8, those special chars are stored over two UTF-chars.
If you display in ANSI some UTF-8 text, it is rendered like this : áéoúöüóuÃ
You see that á becomes á So rendering the first char ($s[0]) would only display the "Ã", which is an incomplete character
Upvotes: 0
Reputation: 157828
It is absolutely correct behavior.
if you want to get a first letter from a multi-byte string, not first byte from binary string, you have to use mb_substr()
:
mb_internal_encoding("UTF-8");
echo mb_substr($s,0,1);
Upvotes: 3
Reputation: 37365
You should use mb_* functions for multibyte strings. mb_substr() in your case.
Upvotes: 2