Search code examples
phplinuxlocalizationinternationalizationlocale

PHP Locale setting for zip code formatting


I am trying to validate post/zip codes for a very international site using the locale settings in Linux using PHP. If it works it would save me tons of time. I've checked the LC_ADDRESS settings in the installed locales and see that the pattern for validation is there for each language/market.

locale -c LC_ADDRESS

How do I access this information using PHP? localeconv() does not include any information about local address validation.


Solution

  • Seems like noone actually have done this. I am guessing it would take improvements to the PHP localeconv() function to actually read the entire thing, and that would be a feature request to them.

    In the meantime I got the advice to fetch the data from http://i18napis.appspot.com/address and that actually contains the same information as the locale LC_ADDRESS and LC_PHONE does, so I am all good even though it means making an extra outgoing HTTP call.