I have credit card number which I want to mask as below:
$cc = 1234123412341234
echo cc_masking($cc)
1234XXXXXXXX1234
function cc_masking($number) {.....}
If you wish to show only last 4 digits, here is a dynamic way. Works with both credit cards, ACH numbers or anything:
https://gist.github.com/khoipro/815ea292e2e87e10771474dc2ef401ef
$variable = '123123123';
$length = strlen($variable);
$output = substr_replace($variable, str_repeat('X', $length - 4), 0, $length - 4);
echo $output;