PHP hidden IP address after two-bit display as an asterisk method _php tips

Source: Internet
Author: User

The example in this article describes the two-bit method of displaying an asterisk after PHP hides the IP address. Share to everyone for your reference. The implementation methods are as follows:

We are in a lot of public websites will encounter the user's IP when the next few IP segments appear as asterisks, so good protection of the user's privacy, interested friends can take a look.

PHP is formatted with the IP address, hiding the next bit.
Example

Copy Code code as follows:
<?php
Hide the later one
return Preg_replace ('/(\d+) \. ( \d+) \. (\d+) \. (\d+)/is ', "$1.$2.$3.*", $IP);

Hide IP last few for *
Echo ereg_replace ("[^\.] {1,3}$ "," * ", $IP);
?>

Example
PHP to implement a hidden IP address last paragraph or the last two ways
Copy Code code as follows:
<?php
--Hidden IP after several
$ip = ' 127.0.0.1 ';
$reg 1 = '/((?: \ D+\.) {3}) \d+/';
$reg 2= ' ~ (\d+) \. (\d+) \. (\d+) \. (\d+) ~ ';
Echo preg_replace ($reg 1, "\\1*", $ip);//The above output is: 127.0.0.*
echo "------------------<br/>";
Echo Preg_replace ($reg 2, "$1.$2.*.*", $ip);//The above output is: 127.0.*.*
?>

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

There are, of course, arrays like the. After separating the array 2, 3 to replace it can be or combined 0,1 array.

I hope this article will help you with your PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.