php codeigniter postcode search!

一个人想着一个人 提交于 2019-12-13 06:35:10

问题


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!?


回答1:


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})



来源:https://stackoverflow.com/questions/6316152/php-codeigniter-postcode-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!