PHP code example of hyqo / ip-utils

1. Go to this page and download the library: Download hyqo/ip-utils library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hyqo / ip-utils example snippets


IpInterface::isValid(string $ip): bool;
IpInterface::isMatch(string $ip, string|array $subnets): bool;
IpInterface::normalize(string $ip): string;
IpInterface::port(string $ip): ?int;

use Hyqo\Utils\Ip\Ip;

Ip::isValid('192.168.1.0'); //true
Ip::isValid('0:0:0:0:0:0:0:1'); //true

Ip::isMatch('131.0.72.199', '131.0.72.0/22'); //true
Ip::isMatch('131.0.76.199', '131.0.72.0/22'); //false

Ip::isMatch('132.0.72.199', ['131.0.72.0/22', '192.168.1.0/31']); //true

Ip::normalize('127.0.0.1:80'); //127.0.0.1
Ip::normalize('[::1]:80'); //::1

Ip::port('127.0.0.1:80'); //80
Ip::port('[::1]:80'); //80