Hi, I am trying to get the users ip address and convert it to the ip range. For example, $_SERVER['REMOTE_ADDR'] = 1.1.1.1 and I want to change it to 1.1.1.0. So $ip_range = 1.1.1.0 Any thoughts?
From your example this would make the last octet zero: $range = preg_replace("#([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\.[0-9]{1,3}#", "$1.0", $_SERVER[REMOTE_ADDR]); -the mole
use javascript var ipaddree=1.1.1.1 var n=ipaddree.length ipaddree.setChar(n-1,'0') now ipaddree value is 1.1.1.0
Why should he use JavaScript? It can be tampered with and not all users have JavaScript. And here's a simpler regex: $ip_range = preg_replace('/[0-9]+$/', '0', $_SERVER['REMOTE_ADDR']); PHP: