Parsing International Phone Numbers
Posted on 2007-12-02
I am trying to write a routine to parse international phone numbers, more specifically I want to extract the country code. I have a table of all the country codes, however, with variable numbering systems in Europe, I'm thinking it may be tough to do so reliably.
In calculating the country codes I hope they have arranged them so
that there is no way to overlap. For instance, if one country has
12345 (A) and another has 123 (B), then if I search for 123, I'll get
two hits, but only one is right. I can get around this by checking the
longest ones first
What happens if country B has a phone number like
123454545454545 where 123 is the country code and 454545454545 is the number
If I don't do it right, I could also accidentally get a hit on country A which has a country code of 12345.
I'm currently writing this routine in PHP. I'm not sure what section this would really go under.