Jump to content

explode()


vchris
 Share

Recommended Posts

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...