cooldude832 Posted October 15, 2007 Share Posted October 15, 2007 I have a field that stores phone numbers as flat digits (1555555555) is 1(555)555.5555 and I was wondering if there is a way to turn digits to a phone nubmer based on country? anyone heard of anything like that Quote Link to comment https://forums.phpfreaks.com/topic/73338-numbers-to-a-phone-number/ Share on other sites More sharing options...
MadTechie Posted October 15, 2007 Share Posted October 15, 2007 erm.. do you mean like this <?php $tel = "(15555555555)"; //added a 5 as it didn't make sense! $tel = preg_replace('/\((\d?)([0-9]{3})[-. ]?([0-9]{3})[-. ]?([0-9]{4})\b\)/s', '+\1 (\2) \3-\4', $tel ); ?> +1 (555) 555-5555 Quote Link to comment https://forums.phpfreaks.com/topic/73338-numbers-to-a-phone-number/#findComment-370068 Share on other sites More sharing options...
Barand Posted October 15, 2007 Share Posted October 15, 2007 I posted this earlier today http://www.phpfreaks.com/forums/index.php/topic,163564.0.html Using that function you could php $tel = array ( 'US' => '+1 (###) ###.####', 'UK' => '+44 ### ### ####' ); $phone = '5555555555'; $loc = 'US'; echo format_template ($phone, $tel[$loc]), '<br>'; $phone = '5555555555'; $loc = 'UK'; echo format_template ($phone, $tel[$loc]), '<br>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/73338-numbers-to-a-phone-number/#findComment-370082 Share on other sites More sharing options...
MadTechie Posted October 15, 2007 Share Posted October 15, 2007 Hummm, hope its not homework lol Quote Link to comment https://forums.phpfreaks.com/topic/73338-numbers-to-a-phone-number/#findComment-370183 Share on other sites More sharing options...
cooldude832 Posted October 15, 2007 Author Share Posted October 15, 2007 Na trying to rebuild phone numbers for a site, but make it dependent on the users location. But i'm debating if I want it in terms of end user or the person's number they are viewing Quote Link to comment https://forums.phpfreaks.com/topic/73338-numbers-to-a-phone-number/#findComment-370231 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.