开发者

Get first UTF-8 char from string and save in DB

开发者 https://www.devze.com 2022-12-15 11:42 出处:网络
I have a problem with inserting a letter that is not an A-Z char. For example: $fullTag = \'świat\'; A \'letter\' should contains ś

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 ?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消