What should I do if mysql intercepts a string?

Source: Internet
Author: User
Tags truncated
Mysql string truncation mysql & nbsp; 4-character string truncation & nbsp; UTF-8 encoding & nbsp; & nbsp; the effects of string truncation are the same now & nbsp; that is, the number of characters intercepted & nbsp; regardless of Chinese and English, what I achieved is & nbsp; for example, if the Chinese character can be truncated by 3 characters, mysql intercepts the string.
Mysql intercepts a string with 4 characters UTF-8 encoded
The effect of string truncation is to intercept a few characters regardless of Chinese and English. what I achieved is:
For example, if three Chinese characters can be captured, can the English characters be automatically recognized as nine characters?
If you are using select left ('find the other object', 3), do not waste time.

------ Solution --------------------
Either Chinese or Spanish is a character.
Why do I count Chinese as one Spanish as three?
------ Solution --------------------
Utf8 gets longer. what is the purpose of byte truncation? when the Buffer length is limited, do you want to ensure that Chinese words are not truncated?

You can use mb_substr to concatenate strings one by one to an empty string, and use strlen to determine whether the number of bytes is too long each time.
------ Solution --------------------
First, judge the string to be intercepted, and then mb_substr.
------ Solution --------------------
To write a function by yourself, you can use it as three characters in English !~~ This is no different from a Chinese character !~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.