PHP code example of cschalenborgh / laravel-ip-anonymizer

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

    

cschalenborgh / laravel-ip-anonymizer example snippets


'providers' => [
    // ...
    Cschalenborgh\IpAnonymizer\IpAnonymizerServiceProvider::class,
];

echo IpAnonymizer::anonymizeIp('133.242.241.12'); 
// returns 133.242.241.0

echo IpAnonymizer::anonymizeIp('133.242.241.12', '255.255.0.0'); 
// returns 133.242.0.0

echo IpAnonymizer::anonymizeIp('2001:db8:85a3::1319:8a2e:370:7344', 'ipv6'); 
// returns 2001:db8:85a3::

echo IpAnonymizer::anonymizeIp('2001:db8:85a3::1319:8a2e:370:7344', 'ipv6', 'ffff:ffff:0000:0000:0000:0000:0000:0000'); 
// returns 2001:db8::

echo (new IpAnonymizer())->anonymizeIPv4('133.242.241.12');
// returns 133.242.241.0

echo (new IpAnonymizer())->anonymizeIPv4('133.242.241.12', '255.0.0.0');
// returns 133.0.0.0

echo (new IpAnonymizer())->anonymizeIPv6('2001:db8:85a3::1319:8a2e:370:7344');
// returns 2001:db8:85a3::

echo (new IpAnonymizer())->anonymizeIPv6('2001:db8:85a3::1319:8a2e:370:7344', 'ffff:ffff:0000:0000:0000:0000:0000:0000');
// returns 2001:db8::