Skip to content

Instantly share code, notes, and snippets.

@thisislawatts
Created July 23, 2012 11:20
Show Gist options
  • Save thisislawatts/3163147 to your computer and use it in GitHub Desktop.
Save thisislawatts/3163147 to your computer and use it in GitHub Desktop.
Turn a String into a href:tel formatted link
function parse_tel_number($tel_number) {
$tel = preg_replace('/\s|\-|\(0\)+/' ,'' ,$tel_number); // Remove " ", -, "(0)"
$tel = preg_replace('/^0/', '0044', $tel); // Prefix single zero string with 0044, defaults to England
$tel = preg_replace('/\+/', '00', $tel); // Replace plus prefixed numbers with 00 to represent international
$tel = preg_replace('/^([^0])/', "00$1", $tel); // Any numbers without 0 at the front are assumed to be international
return "<a href=\"tel:$tel\">$tel_number</a>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment