php隐藏IP地址后两位显示为星号的方法,ip星号
本文实例讲述了php隐藏IP地址后两位显示为星号的方法。分享给大家供大家参考。具体实现方法如下:
我们在很多的公共网站中都会有碰到显示用户的IP时后面几个IP段显示为星号了,这样很好的保护了用户隐私了,感兴趣的朋友可以一起来看看。
php正则格式化IP地址,隐藏后一位。
例子
复制代码 代码如下:
//隐藏后一位
return preg_replace('/(\d+)\.(\d+)\.(\d+)\.(\d+)/is',"$1.$2.$3.*",$ip);
//隐藏IP最后几位为*
echo ereg_replace("[^\.]{1,3}$","*",$ip);
?>
例子
php实现隐藏Ip地址最后一段或者最后两段的方法
复制代码 代码如下:
//--隐藏IP后几位
$ip='127.0.0.1';
$reg1='/((?:\d+\.){3})\d+/';
$reg2='~(\d+)\.(\d+)\.(\d+)\.(\d+)~';
echo preg_replace($reg1,"\\1*",$ip);//以上输出结果为:127.0.0.*
echo "------------------
";
echo preg_replace($reg2,"$1.$2.*.*",$ip);//以上输出结果为:127.0.*.*
?>
例子
复制代码 代码如下:
function suohao($phone){
$p = substr($phone,0,3)."*****".substr($phone,8,3);
return $p;
}
当然还有像数组以.分开之后把数组2,3进行替换就可以了或组合0,1数组就可以了。
希望本文所述对大家的php程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
