Last active
April 19, 2019 16:06
-
-
Save khoipro/815ea292e2e87e10771474dc2ef401ef to your computer and use it in GitHub Desktop.
Mask credit card, account number, etc... with XXXX, show just last 4 last strings/digits.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * You can quick test with http://phptester.net/ | |
| **/ | |
| $account_number = '123123123'; | |
| $credit_card_number = '4242424242424242'; | |
| $account_length = strlen($account_number); | |
| $credit_card_length = strlen($credit_card_number); | |
| $account_output = substr_replace($account_number, str_repeat('X', $account_length - 4), 0, $account_length - 4); | |
| echo '<pre>'; | |
| echo $account_output; // XXXXX3123 | |
| echo '</pre>'; | |
| $credit_card_output = substr_replace($credit_card_number, str_repeat('X', $credit_card_length - 4), 0, $credit_card_length - 4); | |
| echo '<pre>'; | |
| echo $credit_card_output; // XXXXXXXXXXXX4242 | |
| echo '</pre>'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment