Home > Article > Backend Development > PHP uses asterisks to hide some user names, ID cards, IPs, mobile phone numbers, etc._PHP tutorial
1. Imitate Taobao review and purchase records to hide part of the user name. The following code is available for personal testing.
If(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen));
return join(' ', array_slice($t_string[0], $start, $sublen));
}
else
{
$start = $start*2;
$sublen = $sublen* 2;
$strlen = strlen($string);
$tmpstr = '';
for($i=0; $i< $strlen; $i++)
{
if($i>=$start && $i< ($start+$sublen))
{
}
else
If(ord(substr($string, $i, 1))> ;129) $i++;
}
}
}<🎜 //if(strlen($tmpstr)< $strlen ) $tmpstr.= "...";
}
}
}
Usage example:
Copy code
The code is as follows:
The code is as follows:
3. Replace the last digit of the IP with an asterisk
Replace the last digit of the IP with an asterisk and the code is as follows:
Method 1:
4. Five ways to hide mobile phone numbers with * asterisks
//Method 3
$haoma="15012345678";
echo preg_replace("/(d{3})d{5}/","$1*****",$haoma) ;
//Output 150*****678
//Method 4
$tel1 = "13888111188";
$tel2 = "+8613888111188";
$tel3 = "0861088111188";
$tel4 = "086-010-88111188 ";
echo preg_replace('/(^.*)d{4}(d{4})$/','\1****\2',$tel1),"n";
echo preg_replace('/(^.*)d{4}(d{4})$/','\1****\2',$tel2),"n";
echo preg_replace( '/(^.*)d{4}(d{4})$/','\1****\2',$tel3),"n";
echo preg_replace('/(^ .*)d{4}(d{4})$/','\1****\2',$tel4),"n";
//Method 5
//Shield the four digits in the middle of the phone number
function hidtel($phone)
{
$IsWhat = preg_match('/(0[0-9] {2,3}[-]?[2-9][0-9]{6,7}[-]?[0-9]?)/i',$phone); //Landline phone
if($IsWhat == 1)
{
return preg_replace('/(0[0-9]{2,3}[-]?[2-9])[0-9]{3, 4}([0-9]{3}[-]?[0-9]?)/i','$1****$2',$phone);
}
else
{
return preg_replace('/(1[358]{1}[0-9])[0-9]{4}([0-9]{4 })/i','$1****$2',$phone);
}
}