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

Commit

Permalink
update some info
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jan 5, 2019
1 parent bf3852a commit db1c28a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ public static function strlen(string $str, string $encoding = 'UTF-8'): int
return \function_exists('mb_strlen') ? \mb_strlen($str, $encoding) : \strlen($str);
}

/**
* @param string $string
* @return int
*/
public static function utf8Len(string $string): int
{
// strlen: one chinese is 3 char.
// mb_strlen: one chinese is 1 char.
// mb_strwidth: one chinese is 2 char.
return \mb_strlen($string, 'utf-8');
}

/**
* 计算字符长度
* @param string $str
Expand Down

0 comments on commit db1c28a

Please sign in to comment.