* ** Calculate the length of a string (Chinese characters are calculated based on two characters) ** @ paramstring $ str string ** @ returnint * functionmyStrLen ($ str) {$ lengthstrlen (preg_replace ([\ x00-\ x7F], $ str); if ($ length ){... /**
* Calculate the length of a string (Chinese characters are calculated based on two characters)
*
* @ Param string $ str string
*
* @ Return int
*/
Function myStrLen ($ str ){
$ Length = strlen (preg_replace ('/[\ x00-\ x7F]/', '', $ str ));
If ($ length ){
Return strlen ($ str)-$ length + intval ($ length/3) * 2;
}
Else {
Return strlen ($ str );
}
}
/**
* Calculate the length of a string (Chinese characters are counted as one character)
*
* @ Param string $ str string
*
* @ Return int
*/
Function cnForOneBetLen ($ str ){
$ Length = strlen (preg_replace ('/[\ x00-\ x7F]/', '', $ str ));
If ($ length ){
Return strlen ($ str)-$ length + intval ($ length/3) * 1;
}
Else {
Return strlen ($ str );
}
}