我正在使用Google Place API查找地址。 一些輸出的例子:將地址字符串(Google Places API)分段並添加到數組中
Laag-Beugt 2 C, 5473 KB Heeswijk Dinther, Nederland
Industrieweg 36, 8091 AZ Wezep, Nederland
Rijakkerweg 7, 5741 RR Beek en Donk, Nederland
Antoon van Hooffplein 1, 6816 SH Arnhem, Nederland
Lingewal 2A, 6681 LJ Bemmel, Nederland
Lekdijk 120, 3999 NX Tull en Het Waal, Nederland
Concordialaan 2, 4874 NZ Etten-Leur, Nederland
Tibsterwei 4B, 9131 EG Ee, Nederland
Besser Str. 45, 34281 Gudensberg, Duitsland
Fabriekstraat 2, 9470 Denderleeuw, België
現在我想這些字符串切成片,放在陣列,如:
Array
(
[adres] => Laag-Beugt 2C //No space between the 2 and the C
[postcode] => 5473 KB
[plaats] => Heeswijk Dinther
[land] => Nederland
)
Array
(
[adres] => Lekdijk 120
[postcode] => 3999 NX
[plaats] => Tull en Het Waal
[land] => Nederland
)
Array
(
[adres] => Tibsterwei 4B
[postcode] => 9131 EG
[plaats] => Ee //Shortest cityname in the Netherlands
[land] => Nederland
)
Array
(
[adres] => Besser Str. 45
[postcode] => 34281
[plaats] => Gudensberg
[land] => Duitsland
)
Array
(
[adres] => Fabriekstraat 2
[postcode] => 9470
[plaats] => Denderleeuw
[land] => België
)
由於還有的「郵政編碼」(郵編)之間沒有逗號和「 plaats'(城市),我不能使用explode
。輸出將是這樣的:
Array
(
[adres] => Laag-Beugt 2C
[postcode] => 5473 KB Heeswijk Dinther
[plaats] => Nederland
)
在荷蘭一個郵政編碼的格式如下1234 AA
,所以我可以使用正則表達式來打一個逗號連續兩個京後,但在比利時的郵編是1234
格式和德國12345
。所以我有點卡在這裏..
有人可以幫助嗎?
你到目前爲止試過了什麼?張貼你的企圖.. –
@Uchida我已經更新了我的問題。 – JK87