• support@answerspoint.com

Stripping a phone number of its parenthesis, spaces, and hyphens in PHP?

3483

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?

  • PHP

  • asked 7 years ago
  • Gul Hafiz

2Answer


0

With a regexp. Specifically, use the preg_replace function:

$phone = preg_replace('/\D+/', '', $phone);
  • answered 7 years ago
  • Community  wiki

0
preg_replace("/[^0-9]/", "", $phone);
  • answered 7 years ago
  • Community  wiki

Your Answer

    Facebook Share        
       
  • asked 7 years ago
  • viewed 3483 times
  • active 7 years ago

Best Rated Questions