my website currently display comments made from guests and have their username as their IP using <?php echo $_SERVER['REMOTE_ADDR']; ?> this shows their complete IP, how do i make it so it shows something like 71.XX.XXX.432
You could explode the IP string on the periods so you get an array with four entries. You then display $ip[0] . ".xxx.xxx." . $ip[3]
function hide_ip($ipaddress) { return preg_replace( '/\.(\d{1,3})\.(\d{1,3})\./e', '"." . str_repeat("X", strlen("$1")) . "." . str_repeat("X", strlen("$2")) . "."', $ipaddress ); } PHP: Usage example: echo hide_ip('192.168.1.2'); // Prints: 192.XXX.X.2 PHP: