function format_pa_phone_number in Phone 7
Same name and namespace in other branches
- 6 phone.pa.inc \format_pa_phone_number()
Convert a valid Panamenian phone number into standard (+507) 260-4324 format
Parameters
$phonenumber must be a valid nine-digit number (with optional international prefix):
File
- include/
phone.pa.inc, line 55 - CCK field for Panamanian phone numbers
Code
function format_pa_phone_number($phonenumber, $field = FALSE) {
// get digits of phone number
preg_match(PHONE_PA_REGEX, $phonenumber, $matches);
if (preg_match(PHONE_PA_REGEX, $phonenumber, $matches) != 1) {
return $phonenumber;
// not a Panamanian phone number
}
$phonenumber = $matches[3] . '-' . $matches[4];
if (trim($matches[1]) != '') {
$phonenumber = '+' . substr($matches[1], -4) . $phonenumber;
}
elseif ($field && isset($field['phone_country_code'])) {
$phonenumber = '+507 ' . $phonenumber;
}
return $phonenumber;
}