php codeigniter 邮政编码搜索!
我住在英国,我想在我的网站上实现邮政编码搜索框。我从 http://www.easypeasy.com/guides/article 下载数据库.php?article=64。我有一个问题要问,我相信这对于这里的大多数专家来说都是非常愚蠢的。如果我在搜索框中输入邮政编码,我应该如何对其进行子字符串化?我的意思是,假设我的邮政编码是 BS8 1RY,但是数据库中没有 BS81RY 邮政编码,但 BS8 是有的。当我查看邮政编码数据库时,我发现您有 2,3 甚至 4,5 位邮政编码。例如AB10等,有的也是3位数字,如BS8。那么,有没有一个标准来区分邮政编码,然后在sql查询中使用它!?
I am based in UK and I want to implement a postcode search box in my website. I have the database downloaded from http://www.easypeasy.com/guides/article.php?article=64. I have a question to ask, which I am sure is very silly for most of the experts here. If I enter a post code in my search box, how should I substring it? What I mean to say is,suppose my postcode is BS8 1RY, but there is no postcode in database as BS81RY, but BS8 is there. When I was going through the database of postcodes I found that you have 2,3 or even 4,5 digits of post code. For example, AB10 etc. and some are of 3 digits too like BS8. So, is there a standard to distinguish the postcodes and then use it in sql query!?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此正则表达式位于英国邮政编码维基百科页面,它应该可以帮助您识别正确的邮政编码:
(GIR 0AA)|(((A[BL]|B[ABDHLNRSTX]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[HNX]?|F[KY]|G[LUY]? |H[ADGPRSUX]|I[GMPV]|JE|K[ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR] |R[GHM]|S[AEGKLMNOPRSTY]?|T[ADFNQRSW]|UB|W[ADFNRSV]|YO|ZE)[1-9]?[0-9]|((E|N|NW |SE|SW|W)1|EC[1-4]|WC[12])[A-HJKMNPR-Y]|(SW|W)([2-9]|[1-9][0-9 ])|EC[1-9][0-9]) [0-9][ABD-HJLNP-UW-Z]{2})
This regular expression was on the UK postcode wikipedia page, it should help you identify a proper postcode:
(GIR 0AA)|(((A[BL]|B[ABDHLNRSTX]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[HNX]?|F[KY]|G[LUY]?|H[ADGPRSUX]|I[GMPV]|JE|K[ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKLMNOPRSTY]?|T[ADFNQRSW]|UB|W[ADFNRSV]|YO|ZE)[1-9]?[0-9]|((E|N|NW|SE|SW|W)1|EC[1-4]|WC[12])[A-HJKMNPR-Y]|(SW|W)([2-9]|[1-9][0-9])|EC[1-9][0-9]) [0-9][ABD-HJLNP-UW-Z]{2})