Skip to content

Instantly share code, notes, and snippets.

@andrewadcock
Last active July 4, 2016 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewadcock/c2f1438293c83c4e2c4c85f915d744d0 to your computer and use it in GitHub Desktop.
Save andrewadcock/c2f1438293c83c4e2c4c85f915d744d0 to your computer and use it in GitHub Desktop.
Simple Clean Phone Output
/*
* Pass in the phone number in it's natural state, return the numeric only version or pass 'true' as the second parameter and get ther anchor tag as well
*/
function aad_clean_phone( $number_to_clean, $return_type = false ) {
// Simple regex removes any non-numeric characters
$clean = preg_replace( '/\D/', "", $number_to_clean );
// Return full anchor tag is $return_type is true, else just return the stripped phone number
if ( $return_type ) :
return '<a href="tel:' . $clean . '">' . $number_to_clean . '</a>';
else :
return $clean;
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment