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 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); ?> 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
Archived
This topic is now archived and is closed to further replies.