我需要将邮政地址格式化为国家/地区的格式,并且正在寻找能够做到这一点的PHP库。我使用的是使用Locale的zend框架2,但遗憾的是,此时似乎无法处理此问题。
examples
NL RECIPIENT
STREET_NAME HOUSE_NUMBER
POSTAL_CODE LOCALITY
COUNTRY
US RECIPIENT
HOUSE_NUMBER STREET_NAME [STREET_TYPE] [STREET_DIRECTION] [BUILDING] [FLOOR] [APARTMENT]
LOCALITY PROVINCE_ABBREVIATION POSTAL_CODE
COUNTRY
UK RECIPIENT
[FLOOR] [APARTMENT]
[BUILDING]
[HOUSE_NUMBER] STREET_NAME
[DEPENDENT_LOCALITY]
LOCALITY
POSTAL_CODE
(来源http://www.addressdoctor.com/en/countries-data/address-formats.html)
答案 0 :(得分:1)
在制作国际网站时我不得不面对同样的问题。
解决方案是打印由地址的所有连接部分组成的字符串,并在可能的情况下使用Google Map API正确格式化地址。
var g = new google.maps.Geocoder();
function format_address(raw_address) {
g.geocode({address: raw_address}, function (a, status) {
if (status === "OK") {
var splt = a[0].formatted_address.split(new RegExp(",", "g"));
var i = 0;
var res = "";
for(i = 0; i < splt.length-1; i++)
res += $.trim(splt[i]) + '<br/>';
res += $.trim(splt[splt.length-1]);
$('#address').html(res);
}
else if (status == "OVER_QUERY_LIMIT") {
//wait 500ms and try again
}
else {
$('#address').(raw_adress);
}
});
}