address format
1.5.0
一個 PHP 函式庫,用於將街道位址解析為本地化格式。 address format是基於 Google 的 libaddressinput 提供的格式。
我已經編寫了一些基本的單元測試,但它們可能還可以改進。如果您改進了它們,請隨時提交拉取請求!
若要將 AddressFormat 安裝為 Composer 套件,請將其新增至您的composer.json:
"adamlc/address-format" : " ~1.3 "
運行composer update
//Create an address format ter instance
$ address_formatter = new Adamlc AddressFormat Format ;
//Set a locale using a two digit ISO country code.
$ address_formatter -> setLocale ( ' GB ' );
//Set the address parts / attributes
$ address_formatter [ ' ADMIN_AREA ' ] = ' London ' ;
$ address_formatter [ ' LOCALITY ' ] = ' Greenwich ' ;
$ address_formatter [ ' RECIPIENT ' ] = ' Joe Bloggs ' ;
$ address_formatter [ ' ORGANIZATION ' ] = ' Novotel London ' ;
$ address_formatter [ ' POSTAL_CODE ' ] = ' SE10 8JA ' ;
$ address_formatter [ ' STREET_ADDRESS ' ] = ' 173-185 Greenwich High Road ' ;
$ address_formatter [ ' COUNTRY ' ] = ' United Kingdom ' ;
//Get the address in localised format
$ html = true ; // Optional - return the address in HTML <br> instead of n new lines
echo $ address_formatter -> formatAddress ( $ html );
上面的程式碼將產生以下結果:
Joe Bloggs
Novotel London
173-185 Greenwich High Road
Greenwich
London
SE10 8JA
注意:查看 i18n 目錄以查看語言環境的元資料。
以下屬性可用:
管理區
地點
接受者
組織
DEPENDENT_LOCALITY
郵遞區號
排序代碼
街道地址
國家