PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Validate » Validate_ISPN » Bug #5663

13 digit ISBNs?

Details

Request #566313 digit ISBNs?
Submitted2005-10-12 02:04 UTC
Fromseth at pricepages dot org
Assigneddufuz
StatusClosed
PackageValidate_ISPN
PHP VersionIrrelevant
OSMac
Roadmaps(Not assigned)

Comments

[2005-10-12 02:04 UTC] seth at pricepages dot org

Description:
------------
Starting at the beginning of this year, everyone is supposed
to migrate to 13 digit ISBNs. Will the Validate_ISPN class be
supporting this?

[2005-10-12 03:52 UTC] seth at pricepages dot org

No prob about the comment flood, I'd rather more comments
than none at all.

If I were to do it, I would just check the length of the
string that is passed in after preprocessing. If 13, then go
with that, if 10 go with that. You could even translate from
the 10 into the 13, but I think that invalidates the
checksum digit.

Anyway, the two systems are designed to be similar. A valid
ISBN is a valid ISBN, so I would think that you would still
keep BC if you allowed both 13 and 10 digit codes.

[2005-10-12 04:10 UTC] seth at pricepages dot org

While I'm thinking about it, is there any reason for all of
those regular expression calls? You could go from this:

if (preg_match("/[^0-9 IXSBN-]/", $isbn)) {
return false;
}

if (!ereg("^ISBN", $isbn)){
return false;
}

$isbn = ereg_replace('-', '', $isbn);
$isbn = ereg_replace(' ', '', $isbn);
$isbn = eregi_replace('ISBN', '', $isbn);
if (strlen($isbn) != 10) {
return false;
}
if (preg_match("/[^0-9]{9}[^0-9X]/", $isbn)){
return false;
}

$t = 0;
for ($i = 0; $i < strlen($isbn) - 1; $i++){
$t += $isbn[$i]*(10-$i);
}
$f = $isbn[9];

To this:
$isbn = str_replace(array('-', ' '), '', $isbn);
$isbn = eregi_replace('ISBN', '', $isbn);
$len = strlen($isbn);
if ($len != 10 && $len != 13) {
return false;
}
if (!preg_match('/^[0-9]{9,12}[0-9X]$/', $isbn)){
return false;
}

$t = 0;
for ($i = 0; $i < $len - 1; $i++){
$t += $isbn[$i]*(10-$i);
}
$f = $isbn[$len - 1];

(Warning, I'm not setup to test code at this point, so there
may be strange/stupid bugs in it)

[2005-11-14 03:53 UTC] seth at pricepages dot org

To be honest, I don't have much for 13 digit ISBNs. When I
was working on it, though, I found this PDF:
http://www.bisg.org/isbn-13/ISBN13_For_Dummies.pdf

It has a ISBN in there. (But only one)

For being in a transitional period, we seem to be lacking in
sample 13 digit ISBNs.