Re: [OT] Finding country code from full MSISDN in PHP
Jacques Caron <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <6.0.0.22.0.20031113031008.0339c518@pop.interactivemediafactory.net> |
Hi,
At 03:04 13/11/2003, Alex Kinch wrote:
>A bit [OT] but thought I'd ask. Has anyone got a PHP snippet that'll parse
>a full MSISDN and return the country code? I figured one way to do it
>would be run a loop of SQL selects on the first four,three,two,one digits
>of the MSISDN until a match was found - but there must be a better way?
If you have an SQL table with the country codes, then you can do it with a
single query. Something like
SELECT cc FROM countries WHERE ? LIKE prefix||'%' ORDER BY strlen(prefix)
ASC LIMIT 1
should do (at least with PostgreSQL). I believe the ORDER and LIMIT are
only necessary if you handle the 1-NPA cases and then 1 as a fallback for
the US.
Jacques.
-- Interactive Media Factory SARL
SMS, SMS+, IVR & WAP development and services
http://www.imfeurope.com/