fale / isbn
ISBN 库
3.1.0
2019-09-16 21:09 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: ^4.8 || ^5.7 || ^6.5 || ^7.5
README
此库开发旨在为 PHP 开发者提供处理 ISBN(包括 ISBN-10 和 ISBN-13)代码所需的所有工具。
重要提示
dev-master
与 3.x 版本可能存在较大差异。如果您想继续使用 3.x 版本,请使用 3.0.0
或 3.0.x-dev
或 3.x-dev
。
第二重要提示
ISBN 范围会不时更改。数据截至 2017 年 11 月 15 日星期三 13:30:29 CET。
初始化
$isbn = new Isbn\Isbn();
检查
此函数允许您验证 ISBN 代码是 ISBN-10 还是 ISBN-13。这并不验证 ISBN 代码是否有效。要检查 ISBN 代码是否有效,您可以使用 Validation
类。示例
$isbn->check->is10('888183718'); // Will return false $isbn->check->is13('9788889527191'); // Will return true $isbn->check->is13('978888952719'); // Will return false $isbn->check->identify('8881837188'); // Will return 10 $isbn->check->identify('888183718'); // Will return false $isbn->check->identify('9788889527191'); // Will return 13 $isbn->check->identify('978888952719'); // Will return false
验证
此类允许您验证 ISBN-10 和 ISBN-13。示例
$isbn->validation->isbn('8881837188'); // Will return true $isbn->validation->isbn('8881837187'); // Will return false $isbn->validation->isbn('9788889527191'); // Will return true $isbn->validation->isbn('9788889527190'); // Will return false $isbn->validation->isbn10('8881837188'); // Will return true $isbn->validation->isbn10('8881837187'); // Will return false $isbn->validation->isbn13('9788889527191'); // Will return true $isbn->validation->isbn13('9788889527190'); // Will return false
破折号
此类提供简单函数以处理破折号。
添加破折号
此函数允许您在 ISBN-10 和 ISBN-13 中添加正确的破折号。示例
echo $isbn->hyphens->addHyphens('9791090636071'); // Will return 979-10-90636-07-1 echo $hyphens->addHyphens('9791090636071', ' '); // Will return 979 10 90636 07 1
移除破折号
此函数允许您从 ISBN-10 和 ISBN-13 中移除破折号。示例
$isbn->hyphens->removeHyphens('85 359 0277 5'); // Will return 8535902775 $isbn->hyphens->removeHyphens('0-943396-04-2'); // Will return 0943396042 $isbn->hyphens->removeHyphens('978 988 00 3827 3'); // Will return 9789880038273 $isbn->hyphens->removeHyphens('979-10-90636-07-1'); // Will return 9791090636071
修复破折号
此函数允许您修复 ISBN-10 和 ISBN-13 中的破折号
$isbn->hyphens->fixHyphens('85 35902 77 5', ' '); // Will return 85 359 0277 5 $isbn->hyphens->fixHyphens('0 943 3960 42'); // Will return 0-943396-04-2 $isbn->hyphens->fixHyphens('978 988 003827 3', ' '); // Will return 978 988 00 3827 3 $isbn->hyphens->fixHyphens('979-10906-36-07-1'); // Will return 979-10-90636-07-1
校验位
此类允许您计算 ISBN-10 和 ISBN-13 的校验位。示例
$isbn->checkDigit->make('888183718'); // Will return 8 $isbn->checkDigit->make('978888952719'); // Will return 1 $isbn->checkDigit->make10('888183718'); // Will return 8 $isbn->checkDigit->make13('978888952719'); // Will return 1
转换
此类允许您将 ISBN-10 转换为 ISBN-13 并返回。示例
$isbn->translate->to13('8889527191'); // Will return 9788889527191 $isbn->translate->to10('9786028328227'); // Will return 6028328227
开发此库
如果您对某些新功能感兴趣,请请在 GitHub 上打开一个错误报告。如果您已经有了可用的补丁,请打开一个 pull request。在打开 pull request 之前,请确保所有测试都已通过。
生成
- 从 https://www.isbn-international.org/range_file_generation 获取
RangeMessage.xml
文件 cp import/RegistrantElement.php /tmp
cp RangeMessage.xml /tmp
podman run --rm -it --volume /tmp:/tmp php sh -c "cd /tmp && php RegistrantElement.php" > /tmp/out
测试
要检查测试,请运行以下命令
vendor/bin/phpunit tests
从项目根目录。如果 vendor
文件夹为空或不存在,则运行 composer install
或 composer.phar install
,具体取决于您的 composer
安装。