You are here

function format_int_phone_number in Phone 6

Same name and namespace in other branches
  1. 7 include/phone.int.inc \format_int_phone_number()

Formats $phonenumber into the standard representation of international numbers as per E.123.

Parameters

$phonenumber: International phone number to format

Return value

Formatted international phone number

1 call to format_int_phone_number()
PhoneIntTest::assertConversion in tests/phone.int.test

File

./phone.int.inc, line 75

Code

function format_int_phone_number($phonenumber, $field = array()) {
  $phonenumber = trim($phonenumber);
  if ($phonenumber === '') {
    return '';
  }
  $phonenumber = _normalize_country_code($phonenumber, $field);
  $bits = preg_split('/[.()\\[\\]\\- ]/', $phonenumber, -1, PREG_SPLIT_NO_EMPTY);

  // $bits[0] is the country code WITH a plus sign.
  if (isset($bits[1])) {

    // This is the first non-CC segment, so it could have the NDN.
    switch ($bits[1][0]) {
      case 0:
        $bits[1] = substr($bits[1], 1);
        break;
    }
    switch ($bits[1]) {
      case 0:
      case 7:
      case 8:
        array_splice($bits, 1, 1);
        break;
    }
  }
  return implode(' ', $bits);
}