[Asterisk-Dev] Algorithm to parse country code

Terence Parker terence at parker.com.hk
Mon May 10 08:00:24 MST 2004


I am trying to parse a dialed extension in order to deduce the country
code - but can't seem to find any references on efficient ways to do
this... though surely there is a well known good algorithm for this
already?

I plan to store my country details in a MySQL database. Conceptually,
i've already thought that I could successfully match a country from the
dialled extension by reading the countries into an array (or b-tree or
something), and then going through the list several times starting with
the four digit codes, then three digit ones, then two, then one etc...
until a match is made. I assume that country codes do not overlap in a
way which would make this not possible.

Is there a better way to do this? Even if I read all entries and store
them in a tree, I still have to potentially go through the tree four
times to reach the single digit country codes (most notably USA/Canada)
- and every call of the PHP script would search the SQL
database/re-populate the tree... surely this would be very expensive
computationally?

I don't recall a feature in MySQL that allows you to query x number of
characters of a given field only.

Anyone have any better ideas?

Thanks

- Terence




More information about the asterisk-dev mailing list