views:

58

answers:

1

I have a problem with inserting a letter that is not an A-Z char.
For example:

$fullTag = 'świat';

A 'letter' should contains ś

$data = array(
    'full_tag'  => $fullTag,
    'count'     => 1,
    'letter'    => $fullTag[0],
);

But when I execute $table->insert($data);, it inserts me as letter an empty string.

If I set instead of $fullTag[0] a static letter ś - it works fine.

letter column is utf8_polish_ci char(1)

Any ideas ?

+5  A: 

instead of $fullTag[0], you may want to use a multibyte substring function: http://www.php.net/manual/en/function.mb-substr.php .. these mb_* functions are aware of multibyte encodings, $fullTag[0] may only give you one byte.

Jaanus
I tried with `mb_strcut($fullTag, 0, 1, 'UTF-8')` but it does not work.`mb_substr` works - strange.......Do you know why ?Thanks Jaanus ! :-)
hsz
`mb_strcut()` works exactly as substr() or the indexer-access, but, if the last byte appears to be truncated, it simply omits the character. In your case `mb_strcut()` detects that cutting your string at byte 1 will result in a malformed byte-sequence - therefore it omits the last character which is the only character in your case.
Stefan Gehrig