Skip to content
This repository was archived by the owner on Jun 11, 2020. It is now read-only.

Commit db1c28a

Browse files
committed
update some info
1 parent bf3852a commit db1c28a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/StringHelper.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ public static function strlen(string $str, string $encoding = 'UTF-8'): int
146146
return \function_exists('mb_strlen') ? \mb_strlen($str, $encoding) : \strlen($str);
147147
}
148148

149+
/**
150+
* @param string $string
151+
* @return int
152+
*/
153+
public static function utf8Len(string $string): int
154+
{
155+
// strlen: one chinese is 3 char.
156+
// mb_strlen: one chinese is 1 char.
157+
// mb_strwidth: one chinese is 2 char.
158+
return \mb_strlen($string, 'utf-8');
159+
}
160+
149161
/**
150162
* 计算字符长度
151163
* @param string $str

0 commit comments

Comments
 (0)