Skip to content
Advertisement

Stripping a string of its non-numeric characters

I have a phone number stored in $phone, it looks like this: (555) 555-5555. I want it to look like this: 5555555555. How do I take the string and strip it of hyphens, spaces, and parenthesis?

Advertisement

Answer

With a regexp. Specifically, use the preg_replace function:

$phone = preg_replace('/D+/', '', $phone);
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement