formatPhone

Function to format a phone number.

Description

formatPhone( (string) $phone ); 

Parameters (1)

0. $phone (string)
The phone number to format.

Usage

  1. if ( !function_exists( 'formatPhone' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/functions.php'; 
  3.  
  4. // The phone number to format. 
  5. $phone = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = formatPhone($phone); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/functions.php  
  1. function formatPhone($phone) 
  2. $r = cleanPhone($phone); 
  3.  
  4. if(strlen($r) == 11) 
  5. $r = substr($r, 0, 1) . " (" . substr($r, 1, 3) . ") " . substr($r, 4, 3) . "-" . substr($r, 7, 4); 
  6. elseif(strlen($r) == 10) 
  7. $r = "(" . substr($r, 0, 3) . ") " . substr($r, 3, 3) . "-" . substr($r, 6, 4); 
  8. elseif(strlen($r) == 7) 
  9. $r = substr($r, 0, 3) . "-" . substr($r, 3, 4); 
  10.  
  11. /** 
  12. * Filter to do more or less cleaning of phone numbers. 
  13. * @since 1.8.4.4 
  14. * @param string $r The formatted phone number. 
  15. * @param string $phone The original phone number. 
  16. */ 
  17. return apply_filters('pmpro_format_phone', $r, $phone);