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/





Reply via email to