2011-07-13 78 views
4

85.124.99.2显示IP地址的一部分

如何从IP中隐藏最后两个数字?

,并使它像:

86.124.xxx.xxx

+1

http://stackoverflow.com/questions/5224156/how-do-i-mask-hide-an-ip-address-string-using-php-and-正则表达式 –

+1

@ILikeTurtles我猜你实际上并没有将ip从85.xxx改为86.xxx –

回答

11

写到这很快

$ip = "85.124.99.2"; 
$parts = explode('.',$ip); 

$new_ip = $parts[0].'.'.$parts[1].'.xxx.xxx'; 

警告:访问$部分[N]

2
$ip = preg_replace('/\.\d+\.\d+$/', '.xxx.xxx', $ip); 
之前,您应该测试部分的长度
0

消费IP地址和d只打印出你想要的东西。除了在屏幕上打印以外,还不确定除了“制作”以外的其他内容。

0

使用此正则表达式。

(?!\d{1,3}\.\d{1,3}\.)\d 

样品

137.133.204.130 -> 137.133.***.*** 
93.108.72.157 -> 93.108.**.***