1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-29 13:51:37 +08:00

字数统计加上图片字数

This commit is contained in:
koogua 2023-10-01 11:05:53 +08:00
parent 0a86fc3f05
commit 51de0ed94b

View File

@ -14,13 +14,15 @@ class Word
public static function getWordCount($str)
{
$imageWordCount = self::getImageWordCount($str);
$chineseWordCount = self::getChineseWordCount($str);
$str = self::filterChineseWords($str);
$englishWordCount = self::getEnglishWordCount($str);
$count = $chineseWordCount + $englishWordCount;
$count = $imageWordCount + $chineseWordCount + $englishWordCount;
return (int)$count;
}
@ -54,6 +56,11 @@ class Word
return (int)$count;
}
public static function getImageWordCount($str)
{
return 100 * substr_count($str, '<img');
}
public static function filterChineseWords($str)
{
return preg_replace(self::CHINESE_PATTERN, '', $str);