Skip to content

Instantly share code, notes, and snippets.

@adhipg
Created February 17, 2011 12:02
Show Gist options
  • Save adhipg/831580 to your computer and use it in GitHub Desktop.
Save adhipg/831580 to your computer and use it in GitHub Desktop.
Mask a Credit Card - keep the first character, last four characters and any non-numeric characters in the middle.
<?php
preg_replace('/(?!^.?)[0-9](?!(.){0,3}$)/', '*', $credit_card_number);
?>
@PhouvanhKCSV
Copy link

How to also keep first 4 letters?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment