SimplePie_Net_IPv6::removeNetmaskSpec PHP Method

removeNetmaskSpec() public method

Removes a possible existing netmask specification of an IP address.
Since: 1.1.0
public removeNetmaskSpec ( string $ip ) : string
$ip string the (compressed) IP as Hex representation
return string the IP the without netmask
    function removeNetmaskSpec($ip)
    {
        if (strpos($ip, '/') !== false) {
            list($addr, $nm) = explode('/', $ip);
        } else {
            $addr = $ip;
        }
        return $addr;
    }

Usage Example

 public static function Uncompress($ip)
 {
     $uip = SimplePie_Net_IPv6::removeNetmaskSpec($ip);
     $c1 = -1;
     $c2 = -1;
     if (strpos($ip, '::') !== false) {
         list($ip1, $ip2) = explode('::', $ip);
         if ($ip1 === '') {
             $c1 = -1;
         } else {
             $pos = 0;
             if (($pos = substr_count($ip1, ':')) > 0) {
                 $c1 = $pos;
             } else {
                 $c1 = 0;
             }
         }
         if ($ip2 === '') {
             $c2 = -1;
         } else {
             $pos = 0;
             if (($pos = substr_count($ip2, ':')) > 0) {
                 $c2 = $pos;
             } else {
                 $c2 = 0;
             }
         }
         if (strstr($ip2, '.')) {
             $c2++;
         }
         if ($c1 === -1 && $c2 === -1) {
             $uip = '0:0:0:0:0:0:0:0';
         } else {
             if ($c1 === -1) {
                 $fill = str_repeat('0:', 7 - $c2);
                 $uip = str_replace('::', $fill, $uip);
             } else {
                 if ($c2 === -1) {
                     $fill = str_repeat(':0', 7 - $c1);
                     $uip = str_replace('::', $fill, $uip);
                 } else {
                     $fill = str_repeat(':0:', 6 - $c2 - $c1);
                     $uip = str_replace('::', $fill, $uip);
                     $uip = str_replace('::', ':', $uip);
                 }
             }
         }
     }
     return $uip;
 }