Stripping a phone number of its parenthesis, spaces, and hyphens in PHP?
With a regexp. Specifically, use the preg_replace
function:
$phone = preg_replace('/\D+/', '', $phone);
preg_replace("/[^0-9]/", "", $phone);
Cumbersome method for regex avoiders:
implode(array_filter(str_split('(555) 555-5555'), 'is_numeric'));