random1 Posted March 28, 2008 Share Posted March 28, 2008 Hi All, Basic question: How can you insert text (in this case a space character) into a string? For example: transform the credit card number - 0000000000000000 into 0000 0000 0000 0000 Quote Link to comment https://forums.phpfreaks.com/topic/98251-insert-text-into-a-string/ Share on other sites More sharing options...
MadTechie Posted March 28, 2008 Share Posted March 28, 2008 you could do it a few ways <?php $cc = "0000000000000000"; echo substr($cc, 0, 4)." ".substr($cc, 4, 4)." ".substr($cc, 8, 4)." ".substr($cc, 12, 4); ?> <?php $cc = "0000000000000000"; $cc = preg_replace('/(\d{4,4})/', '\1 ', $cc); ?> Quote Link to comment https://forums.phpfreaks.com/topic/98251-insert-text-into-a-string/#findComment-502719 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.