Jump to content

Archived

This topic is now archived and is closed to further replies.

john_6767

hiding credit card details with XXX

Recommended Posts

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

XXXX XXXX XXXX 1234

cheers

Share this post


Link to post
Share on other sites
How are you storing the credit card details? If it's all in one string, you can do it like this:

[code=php:0]
$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");
[/code]

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

Share this post


Link to post
Share on other sites
well thats the setup of every credit card isn't it?

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

or the other guys code :)

Share this post


Link to post
Share on other sites
American Express cards are 15 digits long, not sixteen, so the first example would not work, but the second one would.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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,

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.