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!

Related posts

1 Comment »

  1. Johnny said,

    1 April, 2008 at 10:29 am

    YES, thank you so much, this works brilliant.

RSS feed for comments on this post · TrackBack URL

Leave a Comment

Creative Commons Attribution-ShareAlike 2.0 UK: England & Wales
Creative Commons Attribution-ShareAlike 2.0 UK: England & Wales