隔离州缩写和地址
有没有办法从地址中提取州缩写?我正在为我的网站使用 Joomla 的活动日历扩展,它目前仅将城市和县单独存储在数据库中,但它确实给出了所有地址,即。 123 Main St., Townsville, ID 55555。有没有办法抓取州的两个字母并将其吐出来?即使可能有一种方法可以获取所有出现的两个字母,然后将它们与状态缩写列表进行比较以进行验证。
谢谢 贾森
Is there a way to pull out the state abbreviation from an address? I am using an event calendar extension for Joomla for my site and it currently only stores the city and county separately in the database but it does give the address all together, ie. 123 Main St., Townsville, ID 55555. Is there a way to grab the two letters of the state and spit that out instead? Even if there might be a way to grab all of the two letter occurrences and then compare those to a list of state abbreviations to validate.
Thanks
Jason
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
按照您要求的方式提取信息的问题是,有些人可能会输入整个州名称,有些人可能会缩写州,有些人可能会拼错州......等等。
您不能指望人们给您提供 信息正确的数据...这只是编程的一个事实。
您可以扩展数据库和表单以分别包含状态...更进一步,您可以使用预定的 Ajax 自动完成扩展或下拉列表以确保用户选择正确的状态。
在我的应用中,我在
Region
表中输入美国所有州和加拿大所有省。然后在Person
表中,我有一个int State
。这样我就可以将人的状态加入到区域表中并节省宝贵的数据库空间。但这只是我。The problem with extracting the information the way you're asking to is that some people might enter the entire State name, some might abbreviate the state, some might misspell the state... etc.
You can't count on people to give you the right data... it's just a fact of programming.
You could extend the database and form to include the State separately... going further, you could use a predetermined Ajax AutoComplete extension or a Dropdown List in order to ensure the user is selecting the correct State.
In my apps, I enter all of the US States and all of the Canadian Provinces in a
Region
table. Then in thePerson
table, I have anint State
. That way I can join the person's state to the region table and save valuable db space. But that's just me.