- preg_match: documentation ( source)
- str_replace: documentation ( source)
<?php
function ReformatPhoneNumber($n){
if(!preg_match('/\\d+\\-\\d+\\s\\d+/',$n))throw new Exception('Invalid phone number');
return str_replace(array('-',' '), '', $n);
}
echo ReformatPhoneNumber('23523-235 325');