-->

2012-12-09

memo: isbn

http://ja.wikipedia.org/wiki/ISBN
http://www.linein.org/blog/2007/01/05/convert-isbn10-to-isbn13-with-php/
http://d.hatena.ne.jp/hhelibex/20101001/1285960903

これは上記のサイトのphpのテストです。
"..."の内容は上記のサイトにあります。

<?php
/**
 * ISBN(ISBN-10、ISBN-13)をチェックするユーティリティ。
 * 
 * @author hhelibex
 * @see http://ja.wikipedia.org/wiki/ISBN
 */
class ISBNUtil {
...
}

/**
 * Convert ISBN10 to ISBN13 with PHP
 * 
 * @see http://www.linein.org/blog/2007/01/05/convert-isbn10-to-isbn13-with-php/
 */
function genchksum13($isbn) {
...
}

if (defined("STDIN"))
{
    // usage //
    $list = array(
        '1234567890',
        "4061592998",
        "978-4061592995",
        "4906732135",
        "978-4906732135",
        "978-4-286-13043-9",
        );
    $result = array();

    foreach ($list as $str)
    {
        $isbn13 = "";
        $maybeIsbn = "";

        print "\n" . str_repeat("=", 70) . "\n";

        $maybeIsbn = preg_replace("/[^0-9]/", "", $str);

        switch (true)
        {
        case ISBNUtil::isValidISBN10($maybeIsbn):
            print "\"{$maybeIsbn}\" is isbn10\n";

            echo $isbn13 = isbn10_to_13($maybeIsbn); // returns ISBN13
            print "\n";
            var_dump(ISBNUtil::isValidISBN13($isbn13));
            break;

        case ISBNUtil::isValidISBN13($maybeIsbn):
            print "\"{$maybeIsbn}\" is isbn13\n";
            $isbn13 = $maybeIsbn;
            break;

        default:
            trigger_error("\"{$maybeIsbn}\" is not isbn.", E_USER_NOTICE);
        }

        $result[] = array(
            "original" => $str,
            "converted" => $isbn13,
            );
    }

    print "\n// check\n";

    foreach ($result as $key1 => $val1)
    {
        print "\n" . str_repeat("=", 70) . "\n";
        print "\$key1 = {$key1}\n";
        print "\$val1[\"original\"] = {$val1["original"]}\n";
        print "\$val1[\"converted\"] = {$val1["converted"]}\n";

        foreach ($result as $key2 =>$val2)
        {
            if ($key1 !== $key2 && $val1["converted"] === $val2["converted"])
            {
                print "{$val1["original"]} == {$val2["original"]}\n";
            }
        }
    }
}

0 件のコメント: