Mb_substr Chinese and Japanese are the same length, the display length is different

Source: Internet
Author: User
Two paragraphs Chinese and Japan, from the naked eye is not the same position end, but using the Mb_strlen function to obtain the same length, the test code is as follows:

$str_0 = '[银光字幕组][哆啦A梦新番Doraemon][006][GB][2005.05.20]秘密间谍大作战&Hello!宇';$str_1 = 'Hello Kitty no Happy Birthday (ハローキティとミミィのハッピーバースデー) OVA.mp';$str_2 = 'ARR] Hello Kitty no Fushigi no Kuni no Alice (ハローキティの不思議の国の';$str_3 = '2014.myHD.六福喜事.Hello Babies.粵語中字.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 test result length is 59, but the naked eye obviously see the length is not unified, so that will cause mb_substr this function intercept the data length is not uniform, in the front end will be changed line.

How did everyone solve the problem?

Reply content:

Two paragraphs Chinese and Japan, from the naked eye is not the same position end, but using the Mb_strlen function to obtain the same length, the test code is as follows:

$str_0 = '[银光字幕组][哆啦A梦新番Doraemon][006][GB][2005.05.20]秘密间谍大作战&Hello!宇';$str_1 = 'Hello Kitty no Happy Birthday (ハローキティとミミィのハッピーバースデー) OVA.mp';$str_2 = 'ARR] Hello Kitty no Fushigi no Kuni no Alice (ハローキティの不思議の国の';$str_3 = '2014.myHD.六福喜事.Hello Babies.粵語中字.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 test result length is 59, but the naked eye obviously see the length is not unified, so that will cause mb_substr this function intercept the data length is not uniform, in the front end will be changed line.

How did everyone solve the problem?

... I am here the program output is 59 ... And I've counted two times each. It's all 59 words mb_strlen . And no 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.