Created
November 8, 2018 14:26
-
-
Save andrey-helldar/3055fbe52b6366199f1c92143cf0736f to your computer and use it in GitHub Desktop.
Masking the VIN of car
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 | |
if (!function_exists('vin_mask')) { | |
function vin_mask(string $value) | |
{ | |
$length = strlen($value); | |
$count = 8; | |
$start = mb_substr($value, 0, $count, 'UTF-8'); | |
$end = mb_substr($value, $length - 2, null, 'UTF-8'); | |
$pad = str_pad($end, ($length - $count), '*', STR_PAD_LEFT); | |
return $start . $pad; | |
} | |
} | |
/** | |
* $str = 'ABCDE12F123456789'; | |
* | |
* return vin_mask($str); | |
* // ABCDE12F*******89 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment