PHP Hide IP address after two-bit display as an asterisk method, ip asterisk _php tutorial

Source: Internet
Author: User

PHP hidden IP address Two-bit display as an asterisk method, IP asterisk


This example describes the two-bit display of the PHP hidden IP address as an asterisk. Share to everyone for your reference. The implementation method is as follows:

We in many public websites will encounter the display user's IP when the next few IP segments appear as asterisks, so that the user's privacy is well protected, interested friends can come together to see.

PHP is formatting the IP address, hiding the next bit.
Example
Copy the Code code as follows: <?php
Hide the latter one
return Preg_replace ('/(\d+) \. ( \d+) \. (\d+) \. (\d+)/is ', "$1.$2.$3.*", $IP);

Hide IP The last few are *
Echo ereg_replace ("[^\.] {1,3}$ "," * ", $IP);
?>
Example
PHP implements the method of hiding the last or last two paragraphs of an IP address
Copy the Code code as follows: <?php
--Hide 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 "------------------
";
Echo Preg_replace ($reg 2, "$1.$2.*.*", $ip);//The above output is: 127.0.*.*
?>
Example
Copy the Code code as follows: function Suohao ($phone) {
$p = substr ($phone, 0, 3). " ". substr ($phone, 8, 3);
return $p;
}
Of course there are like arrays with. After separating the array 2, 3 to replace it can be or combine 0,1 array.

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/915424.html www.bkjia.com true http://www.bkjia.com/PHPjc/915424.html techarticle php hides the IP address after the two-bit display as an asterisk method, IP asterisk This article describes the PHP hidden IP address after the two-bit display as an asterisk method. Share to everyone for your reference. Concrete implementation of the party ...

  • 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.