I think one of the issues with using str_replace() and your list of abbreviations is that it will replace all instances wherever they appear in the string. So for example if your street is called “Main Street”, isn’t that going to end up being called “Main Streeteetreet”?
start - Main Street
check for ‘st’, replace with ‘street’ - Main streetreet
check for ‘str’, replace with ‘street’ - Main streeteetreet
new after your reply -
It’s a pain having to deal with abbreviations, or more to the point, dealing with the string not being split into words. Being able to explode the string by spaces and pick off one at a time would make it much easier to deal with. Perhaps you could step through a character at a time until you get a meaningful keyword:
word = ""
while (count < length of (address)) {
word = word + next character of address
is word a keyword or abbreviation?
// deal with keyword
count = count + 1
wend
Once you’ve got the minimum possible abbreviation for a keyword, you can then look at the next few characters to see how far the keyword is abbreviated, then split that out of the address string. Continue looking through the address string until you see another keyword, and the bit between will be the data for the prior keyword.
It would be easier to have some rules, and I suspect this might be a bit of code that you’ll get working for all the samples that you can think of, and a user will break in about ten seconds.
Oh, cross-edit, added loads after your post. Adding spaces makes it better, but your sample strings don’t seem to need spaces after keywords so it won’t always work. Then again, I can’t think of a way that you can code for every eventuality.