tags:

views:

85

answers:

4

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.

A: 
$number = "1234567890";
$number = "###-##-".$number[7].$number[8].$number[9].$number[10];
Pete Herbert Penito
+2  A: 
$ssno = substr_replace($ssno, '#####-', 0, 6);
You
+3  A: 

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

$number = "1234567890";
$number = "###-##-" . substr($number, -4);
Matthew Scharley
+5  A: 

$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...

Jonathan Kuhn
+1 for showing the mySQL alternative.
Pekka