Home >Backend Development >PHP Tutorial >PHP intercepts Chinese string_PHP programming
The following code is used for GB2312 encoding. Intercepting Chinese strings is a headache in PHP. The solution is to determine whether it is a double-byte character based on whether the value is greater than or equal to 128 to avoid garbled characters. Case. However, problems such as mixing Chinese and English, special symbols, etc. always exist. Now I will write a more comprehensive one for reference only:
Program description:
1. The len parameter is based on Chinese characters, 1len Equal to 2 English characters, in order to look better in form
2. If the magic parameter is set to false, Chinese and English will be treated equally, and the absolute number of characters will be taken
3. Especially suitable for Strings encoded with htmlspecialchars()
4. Can correctly handle the entity character mode in GB2312 (
The above is the detailed content of PHP intercepts Chinese string_PHP programming. For more information, please follow other related articles on the PHP Chinese website!