Please enter a URL like: http://www.alixaxel.com/wordpress/wp-content/2007/07/ISBN.php?isbn=ISBN_HERE


<?php

function ISBN($string)
{
    
settype($string'string');

    
$string str_replace(array(' ''-''.'), ''$string);

    if (
strlen($string) == 13)
    {
        return 
EAN($string);
    }

    if (
strlen($string) != 10)
    {
        return 
false;
    }

    
$stack 0;

    for (
$i 0$i 9$i++)
    {
        
$stack += $string[$i] * ($i 1);
    }

    
$check_digit substr($string, -1);

    if (
strtoupper($check_digit) == 'X')
    {
        
$check_digit 10;
    }

    if (
$stack 11 == $check_digit)
    {
        return 
true;
    }

    return 
false;
}

function 
EAN($string)
{
    
settype($string'string');

    
$string str_replace(array(' ''-''.'), ''$string);

    if (
strlen($string) != 13)
    {
        return 
false;
    }

    
$stack 0;
    
$even false;

    for (
$i 12$i >= 0$i--)
    {
        if (
$even === true)
        {
            
$stack += $string[$i] * 3;

            
$even false;
        }

        else
        {
            
$stack += $string[$i];

            
$even true;
        }
    }

    if (
$stack 10 == 0)
    {
        return 
true;
    }

    return 
false;
}

if (!empty(
$_GET['isbn']))
{
    if (
ISBN($_GET['isbn']) === true)
    {
        echo 
'<h2>This ISBN is valid.</h2>';
    }

    else
    {
        echo 
'<h2>This ISBN is INVALID.</h2>';
    }
}

else
{
    echo 
'<h2>Please enter a URL like: http://www.alixaxel.com/wordpress/wp-content/2007/07/ISBN.php?isbn=ISBN_HERE</h2>';
}

echo 
"<hr />";

highlight_file(__FILE__);

?>