PHP code example of stoufa / luhn-agorithm

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

    

stoufa / luhn-agorithm example snippets


  
hnAlgo\Card;

// Valid card number
try {
    $card_number = '378766681165445';
    $card = new Card($card_number);
    echo "$card_number credit card is valid card number". PHP_EOL;
} catch (Exception $e) {
    echo "$card_number credit card is not valid card number". PHP_EOL;
}


// Invalid card number
try {
    $card_number = '378766681165455';
    $card = new Card($card_number);
    echo "$valid_card credit card is valid card number". PHP_EOL;
} catch (Exception $e) {
    echo "$card_number credit card is not valid card number". PHP_EOL;
}