Social Security Number Disguise

I have a social security number that looks like this:

1234567890

I want to show it as follows:

###-##-7890

So, basically, masking the first five digits and entering hyphens.

How can i do this? Thank.

+3
source share
4 answers

$number = '###-##-'.substr($ssn, -4);

just make the start part a string and concat that with the last 4 digits. Either this, or do it in the request itself, asSELECT CONCAT('###-##-', RIGHT(ssn, 4)) FROM customer...

+6
source

This will take the last 4 numbers and mask the rest:

$number = "1234567890";
$number = "###-##-" . substr($number, -4);
+3
source
$ssno = substr_replace($ssno, '#####-', 0, 6);
+2
source
$number = "1234567890";
$number = "###-##-".$number[7].$number[8].$number[9].$number[10];
0
source

Source: https://habr.com/ru/post/1753424/


All Articles