Mb_substr small Chinese knowledge

Source: Internet
Author: User
The mb_substr function is an upgraded version of the substr function. mb_substr supports Chinese truncation without garbled characters. The following describes the basic knowledge of mb_substr. for example, the code is as follows :? Php $ s... the mb_substr function is an upgraded version of the substr function. mb_substr supports Chinese truncation without garbled characters. Next, let's introduce the basic knowledge of mb_substr.

For example, the code is as follows:

 "; Echo" mb_strcut: ". mb_strcut ($ str, 0, 6, 'utf-8'); // The result is as follows:

From the above example, we can see that mb_substr is used to split characters by words, while mb_strcut is used to split characters by bytes, but it does not produce half a character.

In actual use, it needs to be used with mb_strlen. the usage of mb_strlen is similar to that of strlen, but an encoding parameter is added: mb_strlen ("I am a character to be calculated for length ", "gbk"); the result is 11.

For example, if there are more than 20 strings to be intercepted, the code is as follows:

if(mb_strlen($str, "gbk") >20) {    $str = mb_substr($str, 0, 20, "gbk");  }

Note: Make sure that you have the php_mbstring.dll file in Windows/system32. if not, just export it to Windows/system32 from the extensions directory of your Php installation directory.

2. in the windows directory, find php. ini and open the editor. search for mbstring. dll. find; extension = php_mbstring.dll and remove the number; so that the mb_substr function will take effect.


Address:

Reprinted at will, but please attach the article address :-)

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.