This article mainly introduces php's method for counting Chinese characters, including how to use strlen, mb_strlen, mb_strwidth, and other functions and related precautions, for more information about how to calculate the number of Chinese characters in php, see the example in this article. We will share this with you for your reference. The details are as follows:
The previous companies used English for foreign trade. Therefore, the length of statistics was measured using the strlen function, which has never been wrong. but now this error occurs when the Chinese language is counted, now let's test the record.
From the test above, we can see that:
Strlen converts Chinese characters into three bytes
Mb_strlen is counted as 1 byte in both Chinese and English.
Mb_strwidth converts Chinese into 2 bytes.
So we use the mb_strlen function for length statistics.
I hope this article will help you with PHP programming.
For more articles about the php method for counting the number of Chinese characters, refer to the PHP Chinese website!