byrokrat / checkdigit
此包已被废弃,不再维护。未建议替代包。
计算和验证校验和的辅助类
2.1.0
2018-09-29 11:30 UTC
Requires
- php: >=7.0
- ext-bcmath: *
This package is auto-updated.
Last update: 2021-01-03 22:30:27 UTC
README
已废弃!此包已停用,将不再更新。
Checkdigit
计算和验证校验和的辅助类。
安装
composer require byrokrat/checkdigit
Checkdigit 需要 bcmath php 扩展。
API
Calculator
接口定义了两个方法
isValid(string $number): bool
检查数字是否包含有效的校验和。calculateCheckDigit(string $number): string
计算数字的校验和。
实现包括
Modulo10
和Luhn
用于模10校验和(Luhn 是 Modulo10 的简称)。Modulo10Gtin
用于 GTIN 条码中使用的模10校验和变体。Modulo11
用于模11校验和。Modulo97
用于模97校验和。
使用
$luhn = new byrokrat\checkdigit\Luhn; // outputs '1' (true) echo $luhn->isValid('55555551'); // outputs '' (false) echo $luhn->isValid('55555550'); // outputs '1' echo $luhn->calculateCheckDigit('5555555');