PDA

View Full Version : Replacing characters


kjc
09-30-2002, 07:32 PM
Is there a php function (or this could be for javascript instead), that would replace say the first 12 characters of a 16 character word into *.

I have credit cards stored on a database, but want to display them over secure connection, but only the last chars, leaving the first 12 chars as *.

************8004

Any ideas?

mordred
09-30-2002, 10:27 PM
Yes.


$cardNum = "1234567901234567890";
echo preg_replace('/^(.){1,12}/', str_repeat("*", 12), $cardNum);

firepages
10-01-2002, 03:12 AM
str_repeat()

we live and learn ...(had never heard of that one before!)

kjc
10-01-2002, 04:40 PM
Cheers, that is what I wanted. Thanks a lot, :thumbsup: