Jump to content


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...