adding spaces to every 3rd character in a string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mccommunity
Forum Commoner
Posts: 62
Joined: Mon Oct 07, 2002 8:55 am

adding spaces to every 3rd character in a string

Post by mccommunity »

I am trying to take a specific string $string=xfm3muedf7uy; and I am trying to find a way to add spaces after every 3 characters $string=xfm 3mu edf 7uy; What is the best way to do this? Thanks. 8O
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

chunk_split() looks like it may do the trick for ya
http://www.php.net/manual/en/function.chunk-split.php
mccommunity
Forum Commoner
Posts: 62
Joined: Mon Oct 07, 2002 8:55 am

To My Dimension

Post by mccommunity »

Hey man,

You rock.... thanks for your help. This is what I needed.


Mark :lol:
Post Reply