Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Masking a social security number

Tags:

php

I have a Social Security number showing up like this:

1234567890

I want to show it like this:

###-##-7890

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

How can I do that? Thanks.

like image 205
Asim Zaidi Avatar asked Dec 13 '22 21:12

Asim Zaidi


2 Answers

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

just make the starting part a string and concat that with the last 4 digits. Either that or do it in the query itself like SELECT CONCAT('###-##-', RIGHT(ssn, 4)) FROM customer...

like image 69
Jonathan Kuhn Avatar answered Jan 04 '23 16:01

Jonathan Kuhn


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

$number = "1234567890";
$number = "###-##-" . substr($number, -4);
like image 25
Matthew Scharley Avatar answered Jan 04 '23 14:01

Matthew Scharley