Truncate utf8 encoded string, specify width (not length) from first byte

Time:2020-11-18

Intercepts utf8 encoded string, and specifies the width (non length) from the first byte,

It is suitable for the same width interception of limited string length such as news headlines

The results show that the width difference between Chinese and English is the biggest, and the larger the intercepting width is, the more obvious it is

Code example

<?

This work adoptsCC agreementThe author and the link to this article must be indicated in the reprint


When your talent can’t support your ambition, calm down and study