PHP code example of yhdleung / hkid-util

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

    

yhdleung / hkid-util example snippets




$testID = 'C123456';
echo(HKIDUtil::getCheckDigit($testID));  // returns '9'

var_dump(HKIDUtil::validateHKID('AB987654(3)'));   // bool(true)

if(HKIDUtil::validateHKID('AB9876543')){ 
    echo 'valid'; 
}     //returns 'valid'

echo(HKIDUtil::randomHKID());     // returns HKID, e.g. 'LA654668(9)'

for($i = 0; $i < 3; $i++){
    echo(HKIDUtil::randomHKID(0)) . PHP_EOL;
}
// returns HKID without parentheses, e.g. 
// 'Q2127047'
// 'J9009792'
// 'BA1196657'

var_dump(HKIDUtil::validateDate('31-12-1969'));     // bool(true)
var_dump(HKIDUtil::validateDate('01/01/1970'));     // bool(true)
var_dump(HKIDUtil::validateDate('1/1/1970'));       // bool(true)
var_dump(HKIDUtil::validateDate('30/02/1970'));     // bool(false)