Home > Backend Development > PHP Tutorial > How to hide the last two digits of an IP address as asterisks in php, ip asterisk_PHP tutorial

How to hide the last two digits of an IP address as asterisks in php, ip asterisk_PHP tutorial

WBOY
Release: 2016-07-13 10:13:29
Original
1144 people have browsed it

How to hide the last two digits of the IP address as asterisks in php, ip asterisk

The example in this article describes the method of hiding the last two digits of the IP address as asterisks in PHP. Share it with everyone for your reference. The specific implementation method is as follows:

We have encountered in many public websites that when the user's IP is displayed, the following IP segments are displayed as asterisks. This protects user privacy very well. Interested friends can take a look together.

php regular formats the IP address, hiding the last digit.
Example

Copy code The code is as follows:
//Hide the last digit
return preg_replace('/(d+).(d+).(d+).(d+)/is',"$1.$2.$3.*",$ip);

//The last few digits of the hidden IP are *
echo ereg_replace("[^.]{1,3}$","*",$ip);
?>

Example
How to hide the last paragraph or the last two paragraphs of IP address in php
Copy code The code is as follows:
//--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 result is: 127.0.0.*
echo "------------------
";
echo preg_replace($reg2,"$1.$2.*.*",$ip);//The above output result is: 127.0.*.*
?>

Example
Copy code The code is as follows:
function suohao($phone){
$p = substr($phone,0,3)."*****".substr($phone,8,3);
return $p;
}

Of course, there are also arrays like . After separation, just replace arrays 2 and 3 or combine arrays 0 and 1.

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/915424.htmlTechArticleHow to hide the last two digits of an IP address in php and display them as asterisks. The ip asterisk is an example of how php hides IPs. The last two digits of the address are displayed as asterisks. Share it with everyone for your reference. Specific implementation method...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template