Home > Article > Backend Development > How to intercept Chinese text strings in PHP without garbled characters_PHP Tutorial
I found a lot of information on how to intercept Chinese in PHP on the Internet. The most common one is to use the mb_substr function to intercept. This function requires an extension support in php.ini, but I don’t have the permission to modify it and I have to find another way.
substr interception
The substr() function returns a part of a string.
代码如下 | 复制代码 |
$rest = substr("我是中国人", -1); // returns "乱码" echo $rest.' '; $rest = substr("abcdef", -2); // returns "ef" echo $rest.' '; $rest = substr("abcdef", -3, 1); // returns "d" echo $rest.' '; ?> |
Then Baidu Goole said that it can be intercepted by mb_substr
The code is as follows
|
Copy code
|
||||
Operating mechanism tips
| Later a friend told me that most servers do not open
The code is as follows
|
Copy code |