Remove all characters except numbers from a phone number and format by adding dashes in PHP
<?php $number = “(212)222.1111”; //Strip Out Everything Except Numbers $formatted_number=ereg_replace(“[^0-9]”, “”, $number); //Add Dashes $formatted_number = substr ($formatted_number, 0, 3) . ‘-‘ . substr ($formatted_number, 3, 3) . ‘-‘ ….