SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone know how to replace digits in a number with an x, except for the last four digits?

    Example, a credit card number of 1234-1234-1234-1234 would become: xxxx-xxxx-xxxx-1234

    Thanks in advance...
    Luke

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Luke,

    I am sure someone will bust out with a better way because I hate regex, but I did come up with this.

    $str = "1234-1234-1234-1234";
    $r = substr($str, -5, strlen($str));
    $str = substr(ereg_replace("[[:digit:]]", "*", $str), 0, -5).$r;
    print $str;
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Zealot JordanTLClive's Avatar
    Join Date
    Feb 2001
    Location
    Las Vegas, NV
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your using MySQL couldnt you just limit your query to the last 4 digits of the field and then you could just do something like echo "XXXX-XXXX-XXXX-$lastfour";
    -Jordan


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •