这个算法当初写的时候兴奋了一下
$str = "dsdsds075583235043dsffffff83235043ffa01088881111d430721198709115814d";
echo checkNumberString($str);
/*
* @功能:替换字符串中的电话号码为 *
* 包含11位、12位、7位、8位数字s
* @作者:罗杰
* @日期:14.5.23
*/
function checkNumberString($str){
$ret = $str;
$strLen = mb_strlen($str);
if($strLen<7) return;
$j=1;
for($i=0; $i
$f = mb_substr($str, $i,1);
$t = mb_substr($str, $i+1,1);
if(is_numeric($f) && is_numeric($t)){
$j++;
}else{
if($j==11){
$ret = substr_replace($ret, "***********", $i-$j+1, $j);
}
if($j==12){
$ret = substr_replace($ret, "************", $i-$j+1, $j);
}
if($j==7){
$ret = substr_replace($ret, "*******", $i-$j+1, $j);
}
if($j==8){
$ret = substr_replace($ret, "********", $i-$j+1, $j);
}
$j=1;
}
}
return $ret;
}
?>