PHP intercepts Chinese string_PHP programming

微波
Release: 2023-03-11 21:08:01
Original
1172 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!