PHP code example of laraben / vat

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

    

laraben / vat example snippets


$rates = new Laraben\Vat\Rates('/path-for-storing-cache-file.txt');
$rates->getRatesForCountry('NL'); // array with different rates
$rates->getRateForCountry('NL'); // 21
$rates->getRateForCountry('NL', 'standard'); // 21
$rates->getRateForCountry('NL', 'reduced'); // 9
$rates->getRateForCountryOnDate('NL', new \Datetime('2010-01-01'), 'standard'); // 19

$validator = new Laraben\Vat\Validator();
$validator->validateVatNumberFormat('NL203458239B01'); // true (checks format)
$validator->validateVatNumber('NL203458239B01'); // false (checks format + existence)

$validator = new Laraben\Vat\Validator();
$validator->validateIpAddress('256.256.256.256'); // false
$validator->validateIpAddress('8.8.8.8'); // true

$validator = new Laraben\Vat\Validator();
$validator->validateCountryCode('DE'); // true
$validator->validateCountryCode('ZZ'); // false

$countries = new Laraben\Vat\Countries();

// access country name using array access
echo $countries['NL']; // Netherlands

// loop over countries
foreach ($countries as $code => $name) {
    // ...
}

// check if country is in EU
$countries->isCountryCodeInEU('NL'); // true
$countries->isCountryCodeInEU('US'); // false

$geolocator = new Laraben\Vat\Geolocator();
$geolocator->locateIpAddress('8.8.8.8'); // US

$geolocator = new Laraben\Vat\Geolocator('ip2country.info');
$geolocator->locateIpAddress('8.8.8.8'); // US

$geolocator = new Laraben\Vat\Geolocator('ip2c.org');
$geolocator->locateIpAddress('8.8.8.8'); // US