During development, we often intercept strings as needed. if it is a string of English strings, it will not be garbled; but if it is a Chinese string, in many cases, garbled characters may occur due to the length of the truncated part. The following describes how to intercept Chinese strings without garbled characters: during development, we often intercept strings as needed. if it is a string of English strings, we will not see garbled characters during interception. However, if it is a Chinese string, garbled characters may often occur based on the length of the interception. The following describes how to intercept Chinese strings without garbled characters:
$ Length) {$ str = mb_substr ($ string, $ start, $ length, 'utf-8'); return $ str. '... ';}else {return $ string ;}}?>
Related articles:
A small function that inserts a string at a specified position.
Php custom truncation of Chinese Strings-utf8
Code explanation of string format calculation formula using eval in php
The above is the PHP development technique (10)-detailed content of the implementation method of Chinese character string truncation without garbled characters. For more information, please refer to other related articles in the first PHP community!