Source for file ISPN.php
Documentation is available at ISPN.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2005 Piotr Klaban, Damien Seguy, Helgi Þormar |
// | Þorbjörnsson, Pierre-Alain Joye |
// +----------------------------------------------------------------------+
// | This source file is subject to the New BSD license, That is bundled |
// | with this package in the file LICENSE, and is available through |
// | the world-wide-web at |
// | http://www.opensource.org/licenses/bsd-license.php |
// | If you did not receive a copy of the new BSDlicense and are unable |
// | to obtain it through the world-wide-web, please send a note to |
// | pajoye@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Tomas V.V.Cox <cox@idecnet.com> |
// | Pierre-Alain Joye <pajoye@php.net> |
// +----------------------------------------------------------------------+
* Specific validation methods for International Standard Product Numbers (ISPN)
* @author Piotr Klaban <makler@man.torun.pl>
* @author Damien Seguy <dams@nexen.net>
* @author Helgi Þormar Þorbjörnsson <dufuz@php.net>
* @copyright 1997-2005 Piotr Klaban, Damien Seguy, Helgi Þormar Þorbjörnsson,
* @license http://www.opensource.org/licenses/bsd-license.php new BSD
* @version CVS: $Id: ISPN.php,v 1.13 2006/08/17 19:20:51 makler Exp $
* @link http://pear.php.net/package/Validate_ISPN
* Data validation class for International Standard Product Numbers (ISPN)
* This class provides methods to validate:
* - ISBN (International Standard Book Number)
* - ISSN (International Standard Serial Number)
* - ISMN (International Standard Music Number)
* - ISRC (International Standard Recording Code)
* - UCC-12 (U.P.C.) ID number
* - SSCC (Serial Shipping Container Code)
* @author Piotr Klaban <makler@man.torun.pl>
* @author Damien Seguy <dams@nexen.net>
* @author Helgi Þormar Þorbjörnsson <dufuz@php.net>
* @copyright 1997-2005 Piotr Klaban, Damien Seguy, Helgi Þormar Þorbjörnsson,
* @license http://www.opensource.org/licenses/bsd-license.php new BSD
* @version Release: @package_version@
* @link http://pear.php.net/package/Validate_ISPN
$isbn = str_replace(array ('ISBN', '-', ' ', "\t", "\n"), '', $isbn);
} elseif (strlen($isbn) == 10 ) {
* Validate a ISBN 13 number
* The ISBN is a unique machine-readable identification number,
* which marks any book unmistakably.
* This function checks given number according
* Manual can be found at http://www.isbn-international.org
* @param string $isbn number (only numeric chars will be considered)
* @return bool true if number is valid, otherwise false
* @author Helgi Þormar <dufuz@php.net>
* @author Piotr Klaban <makler@man.torun.pl>
$isbn = str_replace(array ('ISBN', '-', ' ', "\t", "\n"), '', $isbn);
* Validate a ISBN 10 number
* The ISBN is a unique machine-readable identification number,
* which marks any book unmistakably.
* This function checks given number according
* Manual can be found at http://www.isbn-international.org
* @param string $isbn number (only numeric chars will be considered)
* @return bool true if number is valid, otherwise false
* @author Damien Seguy <dams@nexen.net>
* @author Helgi Þormar <dufuz@php.net>
static $weights_isbn = array (10 ,9 ,8 ,7 ,6 ,5 ,4 ,3 ,2 );
if (preg_match ("/[^0-9 IXSBN-]/", $isbn)) {
$isbn = strtoupper ($isbn);
$isbn = str_replace (array ('ISBN', '-', ' ', "\t", "\n"), '', $isbn);
if (strlen ($isbn) != 10 ) {
// Requires base class Validate
require_once 'Validate.php';
return Validate ::_checkControlNumber ($isbn, $weights_isbn, 11 , 11 );
* Validate an ISSN (International Standard Serial Number)
* This function checks given ISSN number
* ISSN identifies periodical publications:
* @param string $issn number (only numeric chars will be considered)
* @return bool true if number is valid, otherwise false
* @author Piotr Klaban <makler@man.torun.pl>
static $weights_issn = array (8 ,7 ,6 ,5 ,4 ,3 ,2 );
$issn = strtoupper ($issn);
$issn = str_replace (array ('ISSN', '-', '/', ' ', "\t", "\n"), '', $issn);
// check if this is an 8-digit number
// Requires base class Validate
require_once 'Validate.php';
return Validate ::_checkControlNumber ($issn, $weights_issn, 11 , 11 );
* Validate a ISMN (International Standard Music Number)
* This function checks given ISMN number (ISO Standard 10957)
* ISMN identifies all printed music publications from all over the world
* whether available for sale, hire or gratis--whether a part, a score,
* or an element in a multi-media kit.
* Manual can be found at:
* http://www.ismn-international.org/
* @param string $ismn ISMN number
* @return bool true if number is valid, otherwise false
* @author Piotr Klaban <makler@man.torun.pl>
static $weights_ismn = array (3 ,1 ,3 ,1 ,3 ,1 ,3 ,1 ,3 );
$ismn = strtoupper ($ismn);
$ismn = str_replace (array ('ISMN', '-', '/', ' ', "\t", "\n"), '', $ismn);
// First char has to be M (after ISMN has been stripped if present)
// check if this is a 10-digit number
// Requires base class Validate
require_once 'Validate.php';
return Validate ::_checkControlNumber ($ismn, $weights_ismn, 10 , 10 );
* Validate a ISRC (International Standard Recording Code)
* This function validates an International Standard Recording Code
* which is the international identification system for sound recordings
* and music videorecordings.
* @param string $isrc ISRC number
* @return bool true if number is valid, otherwise false
* @see http://www.ifpi.org/isrc/isrc_handbook.html
* @author David Grant <david@grant.org.uk>
if (!preg_match("/[A-Z]{2}[A-Z0-9]{3}[0-9]{7}/", $isrc)) {
* Validate a EAN/UCC-8 number
* This function checks given EAN8 number
* used to identify trade items and special applications.
* http://www.ean-ucc.org/
* http://www.uc-council.org/checkdig.htm
* @param string $ean number (only numeric chars will be considered)
* @return bool true if number is valid, otherwise false
* @see Validate_ISPN::process()
* @author Piotr Klaban <makler@man.torun.pl>
static $weights_ean8 = array (3 ,1 ,3 ,1 ,3 ,1 ,3 );
return Validate_ISPN ::process ($ean, 8 , $weights_ean8, 10 , 10 );
* Validate a EAN/UCC-13 number
* This function checks given EAN/UCC-13 number used to identify
* trade items, locations, and special applications (e.g., coupons)
* http://www.ean-ucc.org/
* http://www.uc-council.org/checkdig.htm
* @param string $ean number (only numeric chars will be considered)
* @return bool true if number is valid, otherwise false
* @see Validate_ISPN::process()
* @author Piotr Klaban <makler@man.torun.pl>
static $weights_ean13 = array (1 ,3 ,1 ,3 ,1 ,3 ,1 ,3 ,1 ,3 ,1 ,3 );
return Validate_ISPN ::process ($ean, 13 , $weights_ean13, 10 , 10 );
* Validate a EAN/UCC-14 number
* This function checks given EAN/UCC-14 number
* used to identify trade items.
* http://www.ean-ucc.org/
* http://www.uc-council.org/checkdig.htm
* @param string $ean number (only numeric chars will be considered)
* @return bool true if number is valid, otherwise false
* @see Validate_ISPN::process()
* @author Piotr Klaban <makler@man.torun.pl>
static $weights_ean14 = array (3 ,1 ,3 ,1 ,3 ,1 ,3 ,1 ,3 ,1 ,3 ,1 ,3 );
return Validate_ISPN ::process ($ean, 14 , $weights_ean14, 10 , 10 );
* Validate a UCC-12 (U.P.C.) ID number
* This function checks given UCC-12 number used to identify
* trade items, locations, and special applications (e.g., * coupons)
* http://www.ean-ucc.org/
* http://www.uc-council.org/checkdig.htm
* @param string $ucc number (only numeric chars will be considered)
* @return bool true if number is valid, otherwise false
* @see Validate_ISPN::process()
* @author Piotr Klaban <makler@man.torun.pl>
static $weights_ucc12 = array (3 ,1 ,3 ,1 ,3 ,1 ,3 ,1 ,3 ,1 ,3 );
return Validate_ISPN ::process ($ucc, 12 , $weights_ucc12, 10 , 10 );
* Validate a SSCC (Serial Shipping Container Code)
* This function checks given SSCC number
* used to identify logistic units.
* http://www.ean-ucc.org/
* http://www.uc-council.org/checkdig.htm
* @param string $sscc number (only numeric chars will be considered)
* @return bool true if number is valid, otherwise false
* @see Validate_ISPN::process()
* @author Piotr Klaban <makler@man.torun.pl>
static $weights_sscc = array (3 ,1 ,3 ,1 ,3 ,1 ,3 ,1 ,3 ,1 ,3 ,1 ,3 ,1 ,3 ,1 ,3 );
return Validate_ISPN ::process ($sscc, 18 , $weights_sscc, 10 , 10 );
* Does all the work for EAN8, EAN13, EAN14, UCC12 and SSCC
* and can be used for as base for similar kind of calculations
* @param int $data number (only numeric chars will be considered)
* @param int $lenght required length of number string
* @param int $modulo (optionsl) number
* @param int $subtract (optional) numbier
* @param array $weights holds the weight that will be used in calculations for the validation
* @return bool true if number is valid, otherwise false
* @see Validate::_checkControlNumber()
function process($data, $length, &$weights, $modulo = 10 , $subtract = 0 )
//$weights = array(3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3);
//$weights = array_slice($weights, 0, $length);
$data = str_replace(array ('-', '/', ' ', "\t", "\n"), '', $data);
// check if this is a digit number and is the right length
// Requires base class Validate
require_once 'Validate.php';
return Validate ::_checkControlNumber ($data, $weights, $modulo, $subtract);
Documentation generated on Tue, 27 Mar 2007 19:00:04 -0400 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.
|