function engagements_convert_to_pretty_phone_number

7.x engagements.module engagements_convert_to_pretty_phone_number($phoneNumber, $bool_convert_to_valid_first = TRUE)
6.x engagements.module engagements_convert_to_pretty_phone_number($phoneNumber, $bool_convert_to_valid_first = TRUE)
10 calls to engagements_convert_to_pretty_phone_number()
calendar_appointment_content_form_validate in modules/calendar/calendar.module
Custom validate handler for when we save an appointment form. We want to confirm the student is valid, and also store ONLY the cwid.
calendar_content_alter in modules/calendar/calendar.module
Implements hook_content_alter. We want to alter the way that our calendar appointments are displayed.
calendar_schedule_appointment_confirm_form in modules/calendar/calendar.module
The confirmation form the user will see once they have made their schedule selections.
calendar_schedule_appointment_confirm_form_submit in modules/calendar/calendar.module
We passed validation, it's time to actually submit now!
engagements_display_advisee_engagements_page in modules/engagements/engagements.module

... See full list

File

modules/engagements/engagements.module, line 2717
This is the primary module file for the engagements module.

Code

function engagements_convert_to_pretty_phone_number($phoneNumber, $bool_convert_to_valid_first = TRUE) 
 {


  if ($bool_convert_to_valid_first) {
    $phoneNumber = engagements_convert_to_valid_phone_number($phoneNumber);
    if (!$phoneNumber) {
      return FALSE;
    }
  }


  $phoneNumber = preg_replace('/[^0-9]/', '', $phoneNumber);

  if (strlen($phoneNumber) > 10) {
    $countryCode = substr($phoneNumber, 0, strlen($phoneNumber) - 10);
    $areaCode = substr($phoneNumber, -10, 3);
    $nextThree = substr($phoneNumber, -7, 3);
    $lastFour = substr($phoneNumber, -4, 4);

    $phoneNumber = '+' . $countryCode . ' (' . $areaCode . ') ' . $nextThree . '-' . $lastFour;
  }
  else if (strlen($phoneNumber) == 10) {
    $areaCode = substr($phoneNumber, 0, 3);
    $nextThree = substr($phoneNumber, 3, 3);
    $lastFour = substr($phoneNumber, 6, 4);

    $phoneNumber = '(' . $areaCode . ') ' . $nextThree . '-' . $lastFour;
  }
  else if (strlen($phoneNumber) == 7) {
    $nextThree = substr($phoneNumber, 0, 3);
    $lastFour = substr($phoneNumber, 3, 4);

    $phoneNumber = $nextThree . '-' . $lastFour;
  }

  return $phoneNumber;
}