Skip to content

Instantly share code, notes, and snippets.

@andrey-helldar
Created November 8, 2018 14:26
Show Gist options
  • Save andrey-helldar/3055fbe52b6366199f1c92143cf0736f to your computer and use it in GitHub Desktop.
Save andrey-helldar/3055fbe52b6366199f1c92143cf0736f to your computer and use it in GitHub Desktop.
Masking the VIN of car
<?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