php对ip地址的掩码

// 将114.114.114.114修改成114.***.***.114

function formart_ip($ip = '')

{

$arr = explode('.', $ip);


$new_arr = array();


foreach ($arr as $k => $ip_str)

{

$new_arr[$k] = $ip_str;


if(($k == 1) || ($k == 2))

{

$replace = '*';


$length = strlen($ip_str);


for($i = 0; $i < ($length - 1); $i++)

{

$replace .= '*';

}


$new_arr[$k] = substr_replace($ip_str, $replace, 0);

}

}


return $new_arr['0'] . '.' . $new_arr['1'] . '.' . $new_arr['2'] . '.' . $new_arr['3'];

}


你可能感兴趣的:(PHP,return,IP地址,ip地址掩码)