/** * downformat "any" ISBN Number to the very basics * an isbn number is a 10 or 13 digit. with the * 10 digit string, the last digit can be 0-9 and * X as well, all other are 0-9 only * additionally this fucntion can be used to validate * the isbn against correct length and chars * * @param string $isbn ISBN String to normalise * * @return string|false normalised ISBN Number or false if the function was * not able to normalise the input * * @access private */ function _normaliseISBN($isbn) { /* validate input */ $r = settype($isbn, 'string'); if ($r === false) { return false; } /* normalize (trim & case)*/ $isbn = trim($isbn); $isbn = strtoupper($isbn); /* remove lang specific prefix (if any) */ $isbn = ISBN::_normaliseISBNremoveLangSpecific($isbn); /* remove ISBN-10: or ISBN-13: prefix (if any) */ if (strlen($isbn > 8)) { $prefix = substr($isbn, 0, 8); if ($prefix == 'ISBN-10:' || $prefix == 'ISBN-13:') { $isbn = substr($isbn, 8); $isbn = ltrim($isbn); } } /* remove lang specific prefix again (if any) */ $isbn = ISBN::_normaliseISBNremoveLangSpecific($isbn); /* remove "ISBN" prefix (if any)*/ if (substr($isbn, 0, 4) == 'ISBN') { $isbn = substr($isbn, 4); } /* remove cosmetic chars and different type of spaces */ $isbn = str_replace(array('-', ' ', '\\t', '\\n'), '', $isbn); /* take the length to check and differ between versions * sothat a syntaxcheck can be made */ $l = strlen($isbn); if ($l != 10 && $l != 13) { return false; } elseif ($l == 10) { if (!preg_match('/^[0-9]{9}[0-9X]$/', $isbn)) { return false; } } elseif ($l == 13) { if (!ctype_digit($isbn)) { return false; } } return $isbn; }