PHP supports Chinese character truncation functions with multiple file encodings

Source: Internet
Author: User
: This article mainly introduces the Chinese character truncation functions supported by various file encoding in PHP. if you are interested in PHP tutorials, please refer to them. By using a variety of methods to achieve the perfect interception of Chinese strings, without the installation of mbstring and iconv extension support UTF-8, GBK, GB2312, BIG5 encoding, more codes are supported after the above extensions are installed. for details, refer to the function description.
There are three methods
1. mb_substr () requires mbstring extension
2. iconv_substr () requires iconv extension
3. Regular Expression Matching, supported by default
If the preceding method is unavailable, the following method is automatically used.

This code is based on the string intercepted by Midnight and supports common encoding.

1. fixed the issue where mb_substr and iconv_substr were not returned in the original code, which is equivalent to an invalid call.
2. optimized the truncation string suffix and can customize the suffix. The default value is null.

 

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.