You are here

function format_br_phone_number in Phone 7

Same name and namespace in other branches
  1. 6 phone.br.inc \format_br_phone_number()

Formatting for Brazilian Phone Numbers.

Parameters

string $phonenumber:

Return value

string Returns a string containting the phone number with some formatting.

1 call to format_br_phone_number()
BRPhoneNumberTestCase::testPhoneBRFormatting in tests/phone.br.test

File

include/phone.br.inc, line 37
CCK Field for Brazilian phone numbers. (based on CCK Field for French phone numbers.)

Code

function format_br_phone_number($phonenumber, $field = FALSE) {
  $phone = str_replace(array(
    ' ',
    '-',
    '(',
    ')',
  ), '', $phonenumber);
  if (preg_match(PHONE_BR_REGEX, $phone, $matches) != 1) {
    return $phonenumber;

    // this is possible?
  }
  $formatedphone = '';
  if ($field && $field['phone_country_code']) {
    $formatedphone .= '+55 ';
  }
  $formatedphone .= '(' . $matches[3] . ')';
  $formatedphone .= ' ' . $matches[6] . '-';
  $formatedphone .= '' . $matches[7];
  return $formatedphone;
}