Created
July 23, 2012 11:20
-
-
Save thisislawatts/3163147 to your computer and use it in GitHub Desktop.
Turn a String into a href:tel formatted link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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