Jump to content


Photo

hiding credit card details with XXX


  • Please log in to reply
6 replies to this topic

#1 john_6767

john_6767
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 18 August 2006 - 03:24 AM

I am trying to display credit card details in the following format, surely it can't be too hard??

XXXX XXXX XXXX 1234

cheers

#2 Jeremysr

Jeremysr
  • Members
  • PipPipPip
  • Advanced Member
  • 199 posts
  • LocationSaskatchewan, Canada

Posted 18 August 2006 - 03:30 AM

How are you storing the credit card details? If it's all in one string, you can do it like this:

$cardnumber = "1234 5678 0987 6543"; // just for an example

$last_four_digits = $cardnumber[15] . $cardnumber[16] . $cardnumber[17] . $cardnumber[18];
echo ("XXXX XXXX XXXX $last_four_digits");

And in case you didn't know, $cardnumber[15] means the 15th character in that string (starting with the first character being zero)

#3 Jocka

Jocka
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationDallas, Texas

Posted 18 August 2006 - 03:33 AM

well thats the setup of every credit card isn't it?

Just do something simple like this:
$credit_card = $row['creditcard'] // assuming its something like that
$credit_card = substr($credit_card, -4);
$card_num = "XXXX XXXX XXXX" . $credit_card;
something like that should work

or the other guys code :)

#4 john_6767

john_6767
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 18 August 2006 - 03:33 AM

thanks guys, i appreciate your explanations also!

#5 mb81

mb81
  • Members
  • PipPipPip
  • Advanced Member
  • 120 posts

Posted 18 August 2006 - 05:45 AM

American Express cards are 15 digits long, not sixteen, so the first example would not work, but the second one would.

#6 Jeremysr

Jeremysr
  • Members
  • PipPipPip
  • Advanced Member
  • 199 posts
  • LocationSaskatchewan, Canada

Posted 18 August 2006 - 05:53 AM

Well you can change it to whatever you want, I was just explaining how to find a string inside of a string.. Jocka's looks a lot easier though, I didn't know about the substr function.

#7 john_6767

john_6767
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 18 August 2006 - 06:01 AM

yep, i've used jocka's but i didn't know you could find a string inside a string so i'm sure that will be useful in another application,




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users