Jump to content

explode()


vchris

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...