PHP code example of mesour / ip-addresses

1. Go to this page and download the library: Download mesour/ip-addresses 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/ */

    

mesour / ip-addresses example snippets


Assert::true(IpAddressValidator::isIpV6('2a00:5565:2222:800::200e'));

Assert::true(IpAddressValidator::isIpV4('127.0.0.1'));

IpAddressNormalizer::normalizeIpV6('2001:db8:800::ff00:42:8329');

// result is: 2001:0db8:0800:0000:0000:ff00:0042:8329

IpAddressNormalizer::compressIpV6('2001:0db8:0800:0000:0000:ff00:0042:8329');

// result is: 2001:db8:800::ff00:42:8329

$ipAddress = IpAddress::create('127.0.0.1');

$ipAddress->isIpV4(); // result is: true
$ipAddress->isIpV6(); // result is: false
$ipAddress->getValue(); // result is: 127.0.0.1

$ipAddress = IpAddress::create('2001:0db8:0800:0000:0000:ff00:0042:8329');

$ipAddress->isIpV4(); // result is: false
$ipAddress->isIpV6(); // result is: true
$ipAddress->getValue(); // result is: 2001:db8:800::ff00:42:8329