PHP: Making Credit Card Numbers Human-Readable
If you’ve ever tried to enter a 16 digit credit card number all in one blob, you’ll know it’s hard. To make life easier for the person responsible for processing online credit card orders, I needed to split up the credit card number and insert a space every 4 characters.
I’m not very schooled up on RegEx, and after spending ages searching for how to do it, I came across this:
<?php
echo implode(' ',str_split($credit_card_number,4));
?>
Hopefully it saves someone else some time!


Johnny said,
1 April, 2008 at 10:29 am
YES, thank you so much, this works brilliant.