The last two digits of a hidden IP address in php are displayed as asterisks.

Source: Internet
Author: User
Tags arrays

Php regular format IP address, hide the last one.

Example

The code is as follows: Copy code

<? Php
// Hide the last digit
Return preg_replace ('/(\ d + )\. (\ d + )\. (\ d + )\. (\ d +)/is ', "$1. $2. $3. * ", $ ip );
 
// The last number of hidden IP addresses is *
Echo ereg_replace ("[^ \.] {1, 3} $", "*", $ ip );
?>

Example

How to hide the last or last segment of an IP address in php

 

The code is as follows: Copy code
<?
// -- Hide the last few IP addresses
$ Ip = '1970. 0.0.1 ';
$ Reg1 = '/((? : \ D + \.) {3}) \ d + /';
$ Reg2 = '~ (\ D +) \. (\ d + )~ ';
Echo preg_replace ($ reg1, "\ 1 *", $ ip); // The preceding output is 127.0.0 .*
Echo "------------------ <br/> ";
Echo preg_replace ($ reg2, "$1. $2. *. *", $ ip); // The output result is 127. 0 .*.*
?>

Example

The code is as follows: Copy code

Function suohao ($ phone ){
$ P = substr ($ phone,). "*****". substr ($ phone );
Return $ p;
}

Of course, we can replace arrays 2 and 3 with arrays separated by commas (,) or combine arrays 0 and 1.

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.