Mac Ben Mac Ben - 1 year ago 93
PHP Question

Transform ip address to ip range (Start IP - End IP)

I am looking for a function that give me this result:

With only this ip: or ...

Function will look like:

function transform_ip($ip) {
// Method to transform ip the ip-range
// Specify Start IP and End IP
return $result;
echo transform_ip(""); // result:

Answer Source

There are hundreds of ways to trim off everything after the last period. One way is to explode and implode without the last item...

$a = explode('.',$ip); // $a is each number without the periods
pop($a); // Pop off the last number
$ip = implode('.',$a); // Recombine with periods

Now, you can just return your string:

$result = "$ip.0-$ip.255";