/ Published in: PHP
Expand |
Embed | Plain Text
function is_valid_isbn($isbn_number) { $isbn_digits = array_filter(preg_split('//', $isbn_number, -1, PREG_SPLIT_NO_EMPTY), '_is_numeric_or_x'); $isbn_sum = 0; if((10 != $isbn_length) && (13 != $isbn_length)) { return false; } if(10 == $isbn_length) { return (10 == ($isbn_mod = ($isbn_sum % 11))) ? ('x' == mb_strtolower(array_shift($isbn_digits), 'UTF-8')) : ($isbn_mod == array_shift($isbn_digits)); } if(13 == $isbn_length) { return (0 == ($isbn_mod = ($isbn_sum % 10))) ? (0 == array_shift($isbn_digits)) : ($isbn_mod == (10 - array_shift($isbn_digits))); } return false; } function _is_numeric_or_x($val)
You need to login to post a comment.
