cleanPhone

Function to remove special characters from a phone number.

Description

cleanPhone( (string) $phone ); 

NOTE: Could probably replace with preg_replace("[^0-9]", "", $phone)

Parameters (1)

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

Usage

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

Defined (1)

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

/includes/functions.php  
  1. function cleanPhone($phone) 
  2. //if a + is passed, just pass it along 
  3. if(strpos($phone, "+") !== false) 
  4. return $phone; 
  5. //clean the phone 
  6. $phone = str_replace("-", "", $phone); 
  7. $phone = str_replace(".", "", $phone); 
  8. $phone = str_replace("(", "", $phone); 
  9. $phone = str_replace(")", "", $phone); 
  10. $phone = str_replace(" ", "", $phone); 
  11. return $phone;