Created
July 7, 2016 15:26
-
-
Save ximik777/51557b62ca4e5f934845f95b319f7d89 to your computer and use it in GitHub Desktop.
Conversion ID cards in all formats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function cardList($card_id, $uppercase = false) | |
{ | |
if (!$card_id) return []; | |
$arr = []; | |
$arr[0] = $card_id; | |
$arr[1] = implode(array_reverse(str_split($card_id, 2))); | |
if (preg_match('/^[0-9]*$/', $card_id)) { | |
$arr[2] = dechex(substr($card_id, 1)); | |
$arr[3] = implode(array_reverse(str_split($arr[2], 2))); | |
$arr[4] = dechex(strlen($card_id) % 2 ? '0' . $card_id : $card_id); | |
$arr[5] = implode(array_reverse(str_split($arr[4], 2))); | |
} | |
if ($uppercase) { | |
$arr = array_map('strtoupper', $arr); | |
} | |
return $arr; | |
} | |
print_r(cardList('322B3DF6')); | |
print_r(cardList('94131203890')); | |
print_r(cardList('9841694710')); | |
print_r(cardList('4131203890')); | |
print_r(cardList('841694710')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment