KLXN
KLXN

Reputation: 670

Returning first letter when it is language specific character

I have problem with returning first letter from string, when that letter is language specific character.

Reason of that situation is simple: specific character saved in string takes more than one character, and decoding takes place only on display in html with right coding.

When i try do this on php, smarty (truncate to first character), or even mysql i have only part of that letter coded in UTF (for example: � instead of real language specific character).

Is there any way to do this right?

Thanks

Upvotes: 2

Views: 198

Answers (1)

Mark Byers
Mark Byers

Reputation: 837946

Use the multibyte string functions. For example here you can use mb_substr.

$first_char = mb_substr($s, 0, 1, 'UTF-8');

Here I am assuming you are using UTF-8.

Upvotes: 3

Related Questions