1. Go to this page and download the library: Download my-gov/myjpn 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/ */
my-gov / myjpn example snippets
use Exception;
use MyGOV\MyJPN\Exceptions\InvalidMyKADBirthdateException;
use MyGOV\MyJPN\Exceptions\InvalidMyKADBirthplaceCodeException;
use MyGOV\MyJPN\Exceptions\InvalidMyKADCharactersException;
use MyGOV\MyJPN\Exceptions\InvalidMyKADLengthException;
use MyGOV\MyJPN\MyKAD;
try {
$idNo = '980524-14-2347';
$idNo = '980524 14 2347';
$idNo = '980524142347';
$myKad = MyKAD::parse($idNo);
if ($myKad->isValid()) {
echo $myKad; // 980524142347
echo $myKad->formal(); // 980524-14-2347
echo $myKad->formal(false); // 980524142347
echo $myKad->getSpecialNumber(); // 2347
// Gender information. For some early batch of identity number, the gender is unknown.
echo $myKad->isMale() ? 'Male' : 'Female'; // Male
echo $myKad->isFemale() ? 'Female' : 'Male'; // Male
// Place of birth information
echo $myKad->getBirthplaceCode(); // 14
echo $myKad->getState(); // Wilayah Persekutuan (Kuala Lumpur)
echo $myKad->getCountry(); // Malaysia
// Age information
echo $myKad->getBirthDate()->format('Y-m-d'); // 1998-05-24
echo $myKad->getAge(); // 26
echo $myKad->getActualAge(); // 26 years 2 months 4 days
echo $myKad->getAgeOn(date_create('2 years ago')); // 24
echo $myKad->getActualAge(date_create('last year')); // 25 years 2 months 4 days
$myKad->isOver(12) // true. Check is over 12 years old?
$myKad->isOver(18) // true. Check is over 18 years old?
// Age group.
echo $myKad->getAgeGroup(); // Adult.
$myKad->isChildren(); // false
$myKad->isYouth(); // false
$myKad->isAdult(); // true
$myKad->isOldAdult(); // false
$myKad->isSeniorCitizen(); // false
}
} catch (InvalidMyKADLengthException | InvalidMyKADBirthplaceCodeException | InvalidMyKADBirthdateException | InvalidMyKADCharactersException | Exception $throwable) {
echo $throwable->getMessage();
}
use MyGOV\MyJPN\MyKAD;
$myKad = MyKAD::parse('980524-14-2347', exception: false);
if ($myKad->isValid()) {
echo $myKad->getBirthplaceCode(); // 14
echo $myKad->getState(); // Wilayah Persekutuan (Kuala Lumpur)
} else {
echo $myKad->getBirtplaceCode(); // null
echo $myKad->getState(); // null
}
use MyGOV\MyJPN\MyKAD;
$myKad = MyKAD::parse('John Doe (640329-10-7061)', extraction: true);
if ($myKad->isValid()) {
echo $myKad->getBirthplaceCode(); // 10
echo $myKad->getState(); // Selangor
} else {
echo $myKad->getBirtplaceCode(); // null
echo $myKad->getState(); // null
}
$myKad = MyKAD::parse('200618-14-2123')
$myKad->getBirthDate()->format('Y-m-d'); // 2020-06-18
$myKad->getAge(); // 4, assume this year is 2024.
$myKad = MyKAD::parse('200618-14-2123', isElderly: true) // Enable is elderly.
$myKad->getBirthDate()->format('Y-m-d'); // 1920-06-18
$myKad->getAge(); // 104
MyKAD::parse('200618-14-2123')->getState(); // output: Federal Territory (Kuala Lumpur)
MyKAD::parse('200618-14-2123', language: 'ms')->getState(); // output: Wilayah Persekutuan (Kuala Lumpur)
MyKAD::parse('200618-14-2123', language: 'zh-cn')->getState(); // output: 联邦直辖区 (吉隆坡)