PHP code example of kryshtalovich / luhn

1. Go to this page and download the library: Download kryshtalovich/luhn 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/ */

    

kryshtalovich / luhn example snippets


use Kryshtalovich\Luhn\Validate;

// create validator 
$validator = new Validate();

// validate against given values
$valid = $validator->isValid('2775732608516644'); //true
$noValid = $validator->isValid('2775732608516640'); //false

var_dump($valid);
var_dump($noValid);

use Kryshtalovich\Luhn\Generate;

// create generator 
$generator = new Generate();

// generate value

//defined length = 16
$randomCardNumber = $generator->generateCardNumber(); 

//for example American Express card with length = 15 and prefix = '3'
$amexCardNumber = $generator->generateCardNumber(15, '3'); 

var_dump($randomCardNumber);
var_dump($amexCardNumber);