function format_es_phone_number in Phone 5
Same name and namespace in other branches
- 6 phone.es.inc \format_es_phone_number()
- 7 include/phone.es.inc \format_es_phone_number()
Convert a valid Spanish phone number into standard (+34) 916 555 777 format
Parameters
$phonenumber must be a valid nine-digit number (with optional international prefix):
File
- ./
phone.es.inc, line 33
Code
function format_es_phone_number($phonenumber) {
// define regular expression
$regex = "/\n \\D* # optional separator \n ([69]\\d{2}) # first group of numbers\n \\D* # optional separator\n (\\d{3}) # second group\n \\D* # optional separator\n (\\d{3}) # third group\n \\D* # ignore trailing non-digits\n \$/x";
// get digits of phone number
preg_match($regex, $phonenumber, $matches);
// construct ten-digit phone number
$phonenumber = $matches[1] . ' ' . $matches[2] . ' ' . $matches[3];
return $phonenumber;
}