douliang1891 2011-02-23 03:01
浏览 55
已采纳

是否有将美国位置字符串转换为单个部分的最佳做法?

Is there a best practice or common algorithm for implementing conversion of natural search string for locations location (US only) into its separate components?

for example:

City Name, ST 00000

TO

city => City Name
state => ST
zipcode => 00000

This is for a form so i dont need to handle any possible permutation - i can restrict the format to something like: city, st 00000 but i need to be able to handle omission of the any of the segments within the format, so that they optional to some extent... some examples of supported combinations (case insensitive):

00000 // zipcode
0000-00000 //zipcode
city, st / city and state - comma separated
city st // city and state - space separated
city, st 00000 // city state zip
st 00000 // state and zip - though i only really need the zip
city 00000 // city and zip - though i only really need the zip

I can also use a static set of State abbreviations so those could potentially be matched to validate a state segment if needed.

  • 写回答

2条回答 默认 最新

  • douxun4173 2011-02-23 09:14
    关注

    While i was researching I found some other code referenced in another SO question that i used while i was waiting... I modified the code here to support getting the zipcode as well as the city state: http://www.eotz.com/2008/07/parsing-location-string-php

    Others might also find this useful.

    @delphist: THANKS. Once i have time to compare accuracy and performance i may switch to your code if its better - its certainly simpler/shorter! If i do Ill mark it as the official answer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度