用PHP写一个类,实现输入字符串"abbccdddd",输出为"1a2b3c4d"
2 回答
交互式爱情
TA贡献1712条经验 获得超3个赞
preg_replace_callback('/(.)(\1*)/', function($match){return mb_strlen($match[0]).$match[1];}, 'abbcccdddd');
智慧大石
TA贡献1946条经验 获得超3个赞
function processStr($str = "abbcccdddd"){
$result = ''; while(strlen($str) > 0){
$tempStr = substr($str,0,1);
$result .= substr_count($str, $tempStr).$tempStr;
$str = str_replace($tempStr,'',$str);
} return $result;
}- 2 回答
- 0 关注
- 597 浏览
添加回答
举报
0/150
提交
取消
