- var_dump: documentation ( source)
- preg_match: documentation ( source)
- str_replace: documentation ( source)
<?php
function ReformatPhoneNumber($number)
{
if(!preg_match('#^\d(\d[\? ]?){5,10}\d$#', $number))
{
throw new Exception('Invalid phone number');
}
return str_replace(array('-', ' '), '', $number);
}
$a = array('111-111-339-1-1-0');
foreach($a as $b)
{
try{ var_dump(ReformatPhoneNumber($b)); } catch(Exception $e) {}
}