Validate and categorize a GTIN = Global Trade Item Number
A PHP class for:
-
validating if the GTIN is valid
-
retrieving the type of the GTIN:
- EAN-8
- UPC
- EAN-13
- EAN-14
-
retrieving the subtype of the GTIN:
- COMPANY_RESTRICTED
- COUPON
- FUTURE (not valid)
- GID
- ISBN
- ISSN
- REGION_RESTRICTED
-
returning the GTIN in the right format
The requirements are based on version 20.0 of the GS1 General Specifications, see paragraph 1.4.
<?php
include_once('GtinValidator.php');
echo('<html>');
$code = '0417953007527';
$gtin = new gtinValidator($code);
echo 'valid:' . $gtin->isValid() . ', gtin:' . $gtin->getGtin() . ', type:' . $gtin->getType() . ', subtype:' . $gtin->getSubType();
echo('</html>');
?>
- thanks to Ferry Bouwhuis
- thanks to Luke Cousins