This article example describes how to hide the last two digits of the IP address displayed as an asterisk in php. Shared for your reference. Specific implementation method is as follows:
We are in a lot of public websites will have to encounter the display of the user's IP when the last few IP segments show up as an asterisk, so that it is good to protect the user's privacy, interested friends can take a look.
php regular formatting IP address to hide the last bit.
(for) instance
Copy Code The code is as follows.
<?php
//Hide the last digit
return preg_replace('/(\d+)\.(\d+)\.(\d+)\.(\d+)/is',"$1.$2.$3.*",$ip);
//Hide the last digits of the IP as *
echo ereg_replace("[^\.]{1,3}$","*",$ip);
?>
//Hide the last digit
return preg_replace('/(\d+)\.(\d+)\.(\d+)\.(\d+)/is',"$1.$2.$3.*",$ip);
//Hide the last digits of the IP as *
echo ereg_replace("[^\.]{1,3}$","*",$ip);
?>
(for) instance
php method to hide the last paragraph or the last two paragraphs of the Ip address
Copy Code The code is as follows.
<?php
//--Hide the last few digits of the IP
$ip='127.0.0.1';
$reg1='/((?:\d+\.){3})\d+/';
$reg2='~(\d+)\.(\d+)\.(\d+)\.(\d+)~';
echo preg_replace($reg1,"\\1*",$ip);//The above output is 127.0.0.*.
echo "------------------<br/>";
echo preg_replace($reg2,"$1.$2.*. *",$ip);//The above output is: 127.0.*. *.
?>
//--Hide the last few digits of the IP
$ip='127.0.0.1';
$reg1='/((?:\d+\.){3})\d+/';
$reg2='~(\d+)\.(\d+)\.(\d+)\.(\d+)~';
echo preg_replace($reg1,"\\1*",$ip);//The above output is 127.0.0.*.
echo "------------------<br/>";
echo preg_replace($reg2,"$1.$2.*. *",$ip);//The above output is: 127.0.*. *.
?>
(for) instance
Copy Code The code is as follows.
function suohao($phone){
$p = substr($phone,0,3)."*****".substr($phone,8,3);
return $p;
}
$p = substr($phone,0,3)."*****".substr($phone,8,3);
return $p;
}
Of course, there are also arrays like . After separating the arrays, you can replace the arrays 2 and 3 or combine the arrays 0 and 1.
I hope that what I have said in this article will help you in your php programming.