Tag Archives: masking digits of cc

PHP substr_replace

Want to mask part of a string – say a API key or the first 12 digits of a credit card?

Here is a PHP function for doing the job easily

substr_replace(API_USER],"xxxxxxxxxxxx",6,12); //this will replace 12 characters starting from 6th position

substr_replace(API_PASS,"xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",6,28); //this will replace 28 characters starting from 6th position of the string