// 隐藏电话的中间四位
echo parseMobile('15836365252');
function parseMobile($mobile, $start = 4, $len = 4){
$firstLen = $start - 1;
$lastLen = 11 - $len - $firstLen;
$preg = '/(\d{'.$firstLen.'})(\d{'.$lastLen.'})/';
return preg_replace($preg, '$1****$3', $mobile);
}
// 验证邮箱格式是否正确
echo checkEmail('aaa.bbb@163.com');
function checkEmail($mail){
$bool = false;
if(strlen($mail) >= 8 && strlen($mail) <= 40 && (strpos($mail,'@') !== false) && (strpos($mail,'.') !== false)){
$preg = '/^([a-z0-9]+)([a-z0-9_\\.\\-]*)([a-z0-9]+)@([a-z0-9]+)([a-z0-9_\\.\\-]*)([a-z0-9]+)(\\.)([a-z]{2,5})$/i';
preg_match($preg, $mail) AND $bool = true;
}
return $bool;
}
// 隐藏IP地址的后面两段
echo parseIp('192.168.115.210');
function parseIp($ip){
$preg = '/(\d+).(\d+).(\d+).(\d+)/';
return preg_replace($preg, '$1.$2.***.***', $ip);
}