You are here

function tfa_basic_format_number in TFA Basic plugins 7

Format a mobile number.

Parameters

string $number: Phone number.

Return value

string Formatted number.

2 calls to tfa_basic_format_number()
tfa_basic_setup_form in ./tfa_basic.pages.inc
TFA setup form router.
_tfa_basic_plugin_setup_form_overview in ./tfa_basic.pages.inc
Get TFA basic setup action links for use on overview page.

File

./tfa_basic.module, line 512

Code

function tfa_basic_format_number($number) {
  $number = str_replace(array(
    '-',
    ' ',
    '(',
    ')',
  ), '', $number);
  $formatted = $number;
  if (ctype_digit($number) && strlen($number) == 11) {
    $formatted = 'x-xxx-xxx-' . substr($number, 7);
  }
  elseif (ctype_digit($number) && strlen($number) == 10) {
    $formatted = 'xxx-xxx-' . substr($number, 6);
  }
  elseif (ctype_digit($number) && strlen($number) == 7) {
    $formatted = 'xxx-' . substr($number, 3, 4);
  }
  $alterable = array(
    'number' => $number,
    'formatted' => $formatted,
  );
  drupal_alter('tfa_basic_format_number', $alterable);
  return $alterable['formatted'];
}