needs_upgrade Posted April 8, 2010 Share Posted April 8, 2010 Hello guys! I am working on a telephone billing system and i am having difficulties pin-pointing the carrier, the type of call, the country code, the area code and the called number out of a string. Let me present some possible instances of a string: 3111234 - a local call 9293111234 - a local call on a mobile phone 23111234 - call on the same country w/ an area code "2" (some area codes are up to string length of 4 ie. "4741") A8190017347311727 - a call to the US with carrier code "A819", "00" signifies an international call, "1" is the country code of US, "734" is the area code, and "7311727" is the actual called number. As a general rule, a string may: [*]have or do not have a carrier code in front of the string. the length of carrier code is from 1 to 5 [*]have or do not have a country code. the length of country code is from 1 to 4 [*]have or do not have an area code. the length of area code is from 1 to 5 [*]have a landline number or a mobile number in the end of string. landlines are usually of length 7 while mobile numbers are of length 11 I have a database of carrier codes, country codes and their area codes. There are numerous possibilities. Can anyone suggest where should i start? Thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/197983-parsing-strings-of-telephone-numbers/ Share on other sites More sharing options...
oni-kun Posted April 8, 2010 Share Posted April 8, 2010 Yeow, Might be a fairly hard task to accomplish. What I'd start with is some checking the formatting of the number in raw, of course strtr and this would help: if (strlen($phone) == 10) sscanf($phone, "%3s%3s%4s", $area, $prefix, $exchange); } ... if(substr($phone,0,1)=='1') { sscanf($phone, "%1s%3s%3s%4s", $country, $area, $prefix, $exchange); } Here's a list on sprintf formatting: http://php.net/manual/en/function.sprintf.php Although there's a chance there's a flexible class already written onPEAR. Quote Link to comment https://forums.phpfreaks.com/topic/197983-parsing-strings-of-telephone-numbers/#findComment-1038911 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.