php-extended/php-checksum-luhn

A library that implements the php-extended/php-checksum-interface for the luhn algorithm

4.0.0 2022-05-29 07:23 UTC

README

A library that implements the php-extended/php-checksum-interface for the luhn algorithm.

coverage build status

Installation

The installation of this library is made via composer. Download composer.phar from their website. Then add to your composer.json :

	"require": {
		...
		"php-extended/php-checksum-luhn": "^3",
		...
	}

Then run php composer.phar update to install this library. The autoloading of all classes of this library is made through composer's autoloader.

Basic Usage

You may use this library the following way :


use PhpExtended\Checksum\ChecksumLuhn;

$checksum = new ChecksumLuhn();

$data = '<put your digit string here>';
$checked = $checksum->matches(substr($data, 0, -1), substr($data, -1));
// returns true if verified

$signed = $data.$checksum->calculate($data);
// appends the calculated digit to the checksum

License

MIT (See license file).