Mask credit card number in PHP
You can use substr_replace
$var = '1234123412341234';
$var = substr_replace($var, str_repeat("X", 8), 4, 8);
echo $var;
Output
1234XXXXXXXX1234
This should work using substr
:
function ccMasking($number, $maskingCharacter = 'X') {
return substr($number, 0, 4) . str_repeat($maskingCharacter, strlen($number) - 8) . substr($number, -4);
}