Skip to content

Instantly share code, notes, and snippets.

@ximik777
Created July 7, 2016 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ximik777/51557b62ca4e5f934845f95b319f7d89 to your computer and use it in GitHub Desktop.
Save ximik777/51557b62ca4e5f934845f95b319f7d89 to your computer and use it in GitHub Desktop.
Conversion ID cards in all formats
<?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