You are here

function format_ch_phone_number in Phone 7

Same name and namespace in other branches
  1. 6 phone.ch.inc \format_ch_phone_number()

Formatting for Switzerland Phone Numbers.

Parameters

string $phonenumber:

Return value

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

File

include/phone.ch.inc, line 38
CCK Field for Switzerland phone numbers.

Code

function format_ch_phone_number($phonenumber, $field = FALSE) {
  $phone = str_replace(array(
    ' ',
    '-',
    '.',
    '/',
    '(',
    ')',
  ), '', $phonenumber);
  $matches = array();
  if (preg_match(PHONE_CH_REGEX, $phone, $matches) != 1) {
    return $phonenumber;

    // not a switzerland phone number
  }
  $value = ($field && $field['phone_country_code'] ? '+41 (0)' : '0') . substr($matches[2], 0, 2) . ' ' . substr($matches[2], 2, 3) . ' ' . substr($matches[2], 5, 2) . ' ' . substr($matches[2], 7);
  return $value;
}