(1) strlen get string length
(2) Mb_strlen
How to use: Int Mb_strlen (String $str [, String $encoding])
Returns the length of the given string. The encoding parameter is a character encoding. If omitted, the internal character encoding is used.
<?PHP//How to encode a file when testing if UTF8$str ='Chinese a character 1 characters'; echo strlen ($STR).'<br>';// -Echo Mb_strlen ($STR,'UTF8').'<br>';//6Echo Mb_strlen ($STR,'GBK').'<br>';//8Echo Mb_strlen ($STR,'gb2312').'<br>';//Ten?>
GBK encoded state A Chinese character is 2 bytes, UTF-8 encoded in the state of a Chinese character is 3 bytes
In strlen calculation, treats a UTF8 character is 3 length, so "Chinese a character 1 character" length is 3*4+2=14, in Mb_strlen calculation, the selected inner code is UTF8, will be a Chinese character as the length of the calculation, so "the word a 1 character" length is 6.
The two functions can be combined to calculate the number of placeholders for a mixed Chinese-English string (a placeholder for a Chinese character is 2, the English character is 1)
if ((strlen ($company _name) +mb_strlen ($company _name,"UTF8")/2 >$len ) { return109;}
Differences in how strlen and Mb_strlen functions are used in PHP