PHP mb_substr function in actual Encoding

Source: Internet
Author: User

We are using 1. Make sure that the php_mbstring.dll file exists in your Windows/system32 directory. If not, just export the file 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.

The PHP mb_substr function can also intercept the string length. The following example shows the differences:

 
 
  1. <? Php
  2. $ Str = 'so that my string will not contain garbled characters ^_^ ';
  3. Echo "mb_substr:". mb_substr ($ str, 0,7, 'utf-8 ');
  4. // Result:
  5. Echo "<br> ";
  6. Echo "mb_strcut:". mb_strcut ($ str, 0,6, 'utf-8 ');
  7. // Result:
  8. ?>
  9.  

From the above example, we can see that the PHP mb_substr function is to split characters by words, while the mb_strcut function is to split characters by byte, but it does not produce half a 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.