simonp Posted September 25, 2007 Share Posted September 25, 2007 Hi, I have a post string that has eight characters in and need to add five spaces in between each character Eg. $account = "12345678" I need $account = "1 2 3 4 5 6 7 8" What would be the best way to do this? Cheers Simon Link to comment https://forums.phpfreaks.com/topic/70605-solved-adding-spaces-into-a-string/ Share on other sites More sharing options...
Lumio Posted September 25, 2007 Share Posted September 25, 2007 <?php $s = '123456789'; //text $_s = ''; for($i=0;$i<strlen($s);$i++) { //get every single sign if ($i==strlen($s)-1) $_s .= substr($s, $i, 1); else $_s .= substr($s, $i, 1).str_repeat(' ', 5); //add 5 spaces } $s = $_s; echo $ss; ?> Link to comment https://forums.phpfreaks.com/topic/70605-solved-adding-spaces-into-a-string/#findComment-354789 Share on other sites More sharing options...
simonp Posted September 25, 2007 Author Share Posted September 25, 2007 Thanks Lumio - that's ace. Cheers Simon Link to comment https://forums.phpfreaks.com/topic/70605-solved-adding-spaces-into-a-string/#findComment-354794 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.