PHP code example of aldin-sxr / ip-format-tools

1. Go to this page and download the library: Download aldin-sxr/ip-format-tools 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/ */

    

aldin-sxr / ip-format-tools example snippets




Format\IPFormat;

echo IPFormat::ip_to_long('89.0.245.117'); // 1493235061
echo IPFormat::ip_to_long('fd44:5ff2:3::76cd'); // 336649705122095386261522076515346446029

echo IPFormat::long_to_ip(45678892); // 2.185.1.44
echo IPFormat::long_to_ip('567235998141'); // ::84:11e6:71bd

echo IPFormat::ipv4_to_ipv6('34.26.0.75', 'compressed'); // ::ffff:221a:4b
echo IPFormat::ipv4_to_ipv6('34.26.0.75', 'shortened'); // 0:0:0:0:0:ffff:221a:004b
echo IPFormat::ipv4_to_ipv6('34.26.0.75', 'expanded'); // 0000:0000:0000:0000:0000:ffff:221a:004b