You are here

function format_ch_phone_number in Phone 6

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

./phone.ch.inc, line 39
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;
}