You are here

function mailchimp_format_phone_number in Mailchimp 7.5

Same name and namespace in other branches
  1. 7.4 mailchimp.module \mailchimp_format_phone_number()

Formats a phone number string before sending to MailChimp's API.

Currently works only for USA and Canada phone numbers.

Parameters

string $input: The input phone number.

Return value

string The formatted phone number.

See also

http://kb.mailchimp.com/lists/growth/format-guidelines-for-your-import-f...

2 calls to mailchimp_format_phone_number()
mailchimp_mergevars_populate in ./mailchimp.module
Replace an array of merge field placeholder tokens with their values.
mailchimp_signup_subscribe_form_submit in modules/mailchimp_signup/mailchimp_signup.module
Submit handler to add users to lists/audiences on subscription form submission.

File

./mailchimp.module, line 2040
Mailchimp module.

Code

function mailchimp_format_phone_number($input) {
  $base_phone_number = preg_replace('/[^0-9]/s', '', $input);

  // Only attempt to format ten-digit USA and Canada phone numbers.
  if (strlen($base_phone_number) != 10) {
    return $input;
  }

  // Convert phone number to format: "555-123-4567".
  $formatted_number = substr($base_phone_number, 0, 3) . '-' . substr($base_phone_number, 3, 3) . '-' . substr($base_phone_number, 6);
  return $formatted_number;
}