You are here

function format_int_phone_number in Phone 7

Same name and namespace in other branches
  1. 6 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

File

include/phone.int.inc, line 82

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);
}