Re: ISSN for Validate.php
| From: | David Grant | Date: | Wed, 22 Oct 2003 11:14:16 +0000 |
| Subject: | Re: ISSN for Validate.php | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-22900@lists.php.net to get a copy of this message | ||
David Grant said:
> Please find attached issn.php
Looks like it was stripped out. Here you go:
/**
* Validate an ISSN number.
*
* This function validates an ISSN (International Standard Serial Number)
*
* @param string $issn ISSN number in format nnnn-nnn[nx]
* @return bool True if the ISSN number is valid, false otherwise
* @author David Grant <david@davidjonathangrant.info>
*/
function issn($issn)
{
if (!preg_match("/^([0-9]{4})-([0-9]{3}[0-9X])$/", $issn, $matches)) {
return false;
} else {
$issn = $matches[1] . $matches[2];
}
$chksum = 0;
for ($i = 0; $i < strlen($issn) - 1; ++$i) {
$chksum += $issn[$i] * (8 - $i);
}
$chksum += $issn[7] == "X" ? 10 : $issn[7];
if ($chksum % 11) {
return false;
} else {
return true;
}
}
Regards,
David