Home > php教程 > php手册 > body text

php隐藏IP地址后两位显示为星号例子

WBOY
Release: 2016-05-24 12:59:07
Original
1123 people have browsed it

我们在很多的公共网站中都会有碰到显示用户的IP时后面几个IP段显示为星号了,这样很好的保护了用户隐私了,下面我总结了些例子,大家看看吧。

php正则格式化IP地址,隐藏后一位。

例子

<?php
//隐藏后一位
return preg_replace(&#39;/(\d+)\.(\d+)\.(\d+)\.(\d+)/is&#39;,"$1.$2.$3.*",$ip); 
//隐藏IP最后几位为*
echo ereg_replace("[^\.]{1,3}$","*",$ip);
?>
Copy after login

例子

php实现隐藏Ip地址最后一段或者最后两段的方法

<?
//--隐藏IP后几位
$ip=&#39;127.0.0.1&#39;;
$reg1=&#39;/((?:\d+\.){3})\d+/&#39;;
$reg2=&#39;~(\d+)\.(\d+)\.(\d+)\.(\d+)~&#39;;
echo preg_replace($reg1,"\\1*",$ip);//以上输出结果为:127.0.0.*
echo "------------------<br/>";
echo preg_replace($reg2,"$1.$2.*.*",$ip);//以上输出结果为:127.0.*.*
?>
Copy after login

例子

function suohao($phone){
$p = substr($phone,0,3)."*****".substr($phone,8,3);
return $p;
}
Copy after login

当然还有像数组以.分开之后把数组2,3进行替换就可以了或组合0,1数组就可以了。


文章地址:

转载随意^^请带上本文地址!

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template