john_6767 Posted August 18, 2006 Share Posted August 18, 2006 I am trying to display credit card details in the following format, surely it can't be too hard??XXXX XXXX XXXX 1234cheers Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted August 18, 2006 Share Posted August 18, 2006 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) Quote Link to comment Share on other sites More sharing options...
Jocka Posted August 18, 2006 Share Posted August 18, 2006 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 workor the other guys code :) Quote Link to comment Share on other sites More sharing options...
john_6767 Posted August 18, 2006 Author Share Posted August 18, 2006 thanks guys, i appreciate your explanations also! Quote Link to comment Share on other sites More sharing options...
mb81 Posted August 18, 2006 Share Posted August 18, 2006 American Express cards are 15 digits long, not sixteen, so the first example would not work, but the second one would. Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted August 18, 2006 Share Posted August 18, 2006 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. Quote Link to comment Share on other sites More sharing options...
john_6767 Posted August 18, 2006 Author Share Posted August 18, 2006 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, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.