PHP code example of stocker4all / luhn-mod-n
1. Go to this page and download the library: Download stocker4all/luhn-mod-n library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
stocker4all / luhn-mod-n example snippets
use S4A\LuhnModN\LuhnModN;
ew LuhnModN();
$number = 1234567890;
// Generate checksum and return it concatenated to given number
$numberWithChecksum = $luhnModN->createChecksum($number, 10);
echo $numberWithChecksum."\n";
// Generate checksum and return only checksum
$onlyChecksum = $luhnModN->createChecksum($number, 10, false);
echo $onlyChecksum."\n";
// Verify the checksum
if ($luhnModN->hasValidChecksum($numberWithChecksum, 10)) {
echo "Valid checksum\n";
}