phone number cleaner

Phone number cleaner function (probably could use some additional regex wildcards, but):

$pattern = '/([^0-9]+)/i';
$phone = preg_replace($pattern,'', $phone);
echo $phone;

or (be careful with this approach if you want leading zeros):

$phone = (int) filter_var($phone, FILTER_SANITIZE_NUMBER_INT);

Leave a Reply