vchris Posted May 29, 2008 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. Link to comment Share on other sites More sharing options...
Jesdisciple Posted May 29, 2008 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 Link to comment Share on other sites More sharing options...
vchris Posted May 29, 2008 Author Share Posted May 29, 2008 Perfect!Thanks Chris. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.