vchris 3 Posted May 29, 2008 Report Share Posted May 29, 2008 How can I explode every character in a string? I want to add dashes in a phone number if there aren't any. If I get something like 1231231234, I want it to become 123-123-1234. I figured exploding the string would be one way but I can't find out how to explode everything. If there is a better let me know. Quote Link to post Share on other sites
Jesdisciple 0 Posted May 29, 2008 Report Share Posted May 29, 2008 There's definitely a better way, but I can't get to my WAMP right now so this code could very well be wrong. $phone = preg_replace('/^(\d{3})(\d{3})(\d{4})$/', '$1-$2-$3', $phone); EDIT: See http://www.regular-expressions.info/php.html Quote Link to post Share on other sites
vchris 3 Posted May 29, 2008 Author Report Share Posted May 29, 2008 Perfect!Thanks Chris. Quote Link to post Share on other sites
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.