刚写了一个,可能有些情况也判断不到,请大家多测试并提出~
/**
* 查找连续出现指定次数的字符(中文为utf-8)
*
* @param string $str 要查找的字符串
* @param int $count 连续出现的次数
* @param bool $tolower 是否区分大小写,默认 true
* @reutrn array
*/
function find_repeat_chars($str,$count,$tolower = true) {
$repeat_chars = array();
$str = $haystack = $tolower ? strtolower($str) : $str;
preg_match_all("/[xe0-xef][x80-xbf]{2}/",$str,$tmp);
$tt = array();
if(isset($tmp[0]) && !empty($tmp[0])) {
$tt = array_unique($tmp[0]);
$haystack = str_replace($tt,'',$haystack);
}
$chars = array_merge(str_split(count_chars($haystack,3)),$tt);
foreach($chars as $c) {
if(!preg_match('/('.$c.'){'.$count.',}/',$str)) continue;
$repeat_chars[] = $c;
}
return $repeat_chars;
}
$str = '啊啊啊啊啊啊我!abcBb来bbbbB';
var_dump(find_repeat_chars($str,5));