The length of mb_substr is the same in Chinese and Japanese, and the display length is different.

Source: Internet
Author: User
The two Chinese characters and Japanese characters are not in the same position, but the length obtained by using the mb_strlen function is indeed the same. The test code is as follows: {code ...} the length of the test result is 59, but the length is obviously inconsistent with the naked eye. This will cause the mb_substr... the two Chinese characters and Japanese characters are not in the same position, but the length obtained by using the mb_strlen function is indeed the same. The test code is as follows:

$ Str_0 = '[silver subtitle group] [Doraemon] [006] [GB] [2005.05.20] Secret espionage & Hello! Yu '; $ str_1 = 'Hello Kitty no Happy Birthday (please wait until there are too many attempts) OVA. mp '; $ str_2 = 'Arr] Hello Kitty no Fushigi no Kuni no Alice. myHD. lucky luck. hello babies.w.w.gov.ac-3.1920x1080-myfun4u.mkv '; return mb_strlen ($ str_0, 'utf-8 '). '@'. mb_strlen ($ str_1, 'utf-8 '). '@'. mb_strlen ($ str_2, 'utf-8 '). '@'. mb_strlen ($ str_3, 'utf-8 ');

The length of the test results is 59, but it is obvious to the naked eye that the length is not uniform. In this case, the length of the Data intercepted by the mb_substr function is not uniform, and the line break is displayed on the front end.

How do you solve this problem?

Reply content:

The two Chinese characters and Japanese characters are not in the same position, but the length obtained by using the mb_strlen function is indeed the same. The test code is as follows:

$ Str_0 = '[silver subtitle group] [Doraemon] [006] [GB] [2005.05.20] Secret espionage & Hello! Yu '; $ str_1 = 'Hello Kitty no Happy Birthday (please wait until there are too many attempts) OVA. mp '; $ str_2 = 'Arr] Hello Kitty no Fushigi no Kuni no Alice. myHD. lucky luck. hello babies.w.w.gov.ac-3.1920x1080-myfun4u.mkv '; return mb_strlen ($ str_0, 'utf-8 '). '@'. mb_strlen ($ str_1, 'utf-8 '). '@'. mb_strlen ($ str_2, 'utf-8 '). '@'. mb_strlen ($ str_3, 'utf-8 ');

The length of the test results is 59, but it is obvious to the naked eye that the length is not uniform. In this case, the length of the Data intercepted by the mb_substr function is not uniform, and the line break is displayed on the front end.

How do you solve this problem?

... I output 59 in the program here, and then each of them is specially counted twice. It is 59 characters ..mb_strlenNo problem...

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.