: 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.