PHP code example of real-digital / gtin-validator

1. Go to this page and download the library: Download real-digital/gtin-validator 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/ */

    

real-digital / gtin-validator example snippets




use Real\Validator\Gtin;

// create a valid GTIN
$value = '4006381333931';
$gtin = Gtin\Factory::create($value);


// handle errors
$value = 'any invalid value';
try {
    $gtin = Gtin\Factory::create($value);
} catch (Gtin\NonNormalizable $e) {
    // ...
}


// check whether GTIN is valid
$value = '4006381333931';
$isValid = Gtin\Factory::isValid($value);