While working on a recent web development project, I needed to do some processing to customers shipping and billing addresses, specifically stripping out the street suffix from the end of the street line of the address.
In order to do this, I needed a database of common street suffix’s and their abbreviations, like Rd for Road and St for Street.
I found this page on USPS’s website, which lists a number of common street name’s and their corresponding abreviations, but it was in HTML format and not sorted as I needed. So, I spent a bit of time sorting and cleaning these names.
Hopefully, this will save someone else some time and/or give them a starting place for a similar project.
Download File I have uploaded a spreadsheet of common USPS Street Names and Abbreviation.
Description of File
All Streets Tab: This includes all streets and suffixes provided by USPS sorted alphabetically, with duplicates removed.
Priority 1 – 3 Tabs: On the above USPS website, they list the full name(DRIVE,) along with the common abbreviation(Dr,) and then a number of similar, but non-standard abbreviations, such as (DRIV and DRV.) To help speed up the matching of my algorithm, I attempted to sort these by the ones that are most common. Priority 1 and Priority 2 tabs include only the full name and common abbreviation, so DRIVE and Dr, then Priority 3 includes the less common abbreviations DRIV and DRV.
Sorted With Top Level Names First Tab: Since the Priority 1 and Priority 2 tabs were unscientifically eyeball sorted, meaning names I recognized as streets in my area and/or thought were more common, the Sorted With Top Level Names First combines Priority 1 and Priority 2 tabs, sorts them and then puts them at the top of the Priority 3 tab. So, the ones at the top of the list are the common name and abbreviation(DRIVE and Dr) and then at the bottom of the list, you will find the non-standard ones(DRIV and DRV).
I combined the three priority tabs, 1-3, into a single array and converted them to lower case. Then, searched the street address to see if the suffix/street name appears as a single word at the end of the address line.
Below is a basic example of how I am using this to clean the street addresses:
<?php $clean_streets = new clean_street(); $test_cases = array('123 any street', '123 any st.', '123 any st', '123 any STRT', '123 any not_a_suffix', '123 any bypass.'); foreach($test_cases as $test_case){ $test_street = $clean_streets->clean_street_address($test_case); if($test_street === false){ echo "No Suffix Found for '{$test_case}'<br />"; } else{ echo "Clean Street Name = '{$test_street}'<br />"; } } class clean_street{ protected $street_names = array('rd','road','dr','drive','st','street','hwy','highway','ave','avenue','blvd','boulevard','byp','bypass','cir','circle','clf','cliff','clb','club','cmn','common','cor','corner','ct','court','cv','cove','crk','creek','xing','crossing','xrd','crossroad','expy','expressway','ext','extension','est','estate','frk','fork','fwy','freeway','ft','fort','gdn','garden','gtwy','gateway','gln','glen','grn','green','grv','grove','hbr','harbor','hts','heights','hl','hill','inlt','inlet','jct','junction','ln','lane','mtwy','motorway','mt','mount','opas','overpass','pkwy','parkway','pass','path','pike','pl','place','plz','plaza','pt','point','prt','port','rte','route','run','shl','shoal','sq','square','ter','terrace','trwy','throughway','trce','trace','trak','track','trl','trail','turnpk','turnpike','un','union','vly','valley','walk','way','aly','alley','anx','anex','arc','arcade','byu','bayou','bch','beach','bnd','bend','blf','bluff','bluffs','blfs','btm','bottom','br','branch','brg','bridge','brk','brook','brks','brooks','bg','burg','bgs','burgs','cp','camp','cyn','canyon','cpe','cape','cswy','causeway','ctr','center','ctrs','centers','cirs','circles','clfs','cliffs','cmns','commons','cors','corners','crse','course','cts','courts','cvs','coves','cres','crescent','crst','crest','xrds','crossroads','curv','curve','dl','dale','dm','dam','drs','drives','dv','divide','ests','estates','exts','extensions','fall','fls','falls','fry','ferry','fld','field','flds','fields','flat','flt','flts','flats','frd','ford','frds','fords','frst','forest','frg','forge','frgs','forges','frks','forks','gdns','gardens','glns','glens','grns','greens','grvs','groves','hbrs','harbors','hvn','haven','holw','hollow','is','island','iss','islands','isle','jcts','junctions','ky','key','kys','keys','knl','knoll','knls','knolls','lk','lake','lks','lakes','land','lndg','landing','lgt','light','lgts','lights','lock','lck','lcks','locks','ldg','lodge','loop','mall','mnr','manor','mnrs','manors','mdw','meadow','mdws','meadows','mews','ml','mill','mls','mills','msn','mission','mtn','mountain','mtns','nck','neck','orch','orchard','oval','park','parks','parkways','passage','psge','pne','pine','pnes','pines','pln','plain','plns','plains','pts','points','prts','ports','pr','prairie','radl','radial','ramp','rnch','ranch','rpd','rapid','rpds','rapids','rst','rest','rdg','ridge','rdgs','ridges','riv','river','rds','roads','row','rue','shls','shoals','shr','shore','shrs','shores','skwy','skyway','spg','spring','spgs','springs','spur','spurs','sqs','squares','sta','station','stra','stravenue','strm','stream','sts','streets','smt','sumit','trfy','trafficway','trlr','trailer','tunl','tunnel','upas','underpass','vlys','valleys','via','viaduct','vw','view','vws','views','vlg','village','vlgs','villages','vl','ville','vis','vista','wall','walks','ways','wl','well','wls','wells','allee','ally','annex','annx','av','aven','avenu','avn','avnue','bayoo','bluf','bot','bottm','boul','boulv','brdge','brnch','bypa','bypas','byps','canyn','causwa','cen','cent','centr','centre','circ','circl','cmp','cnter','cntr','cnyn','crcl','crcle','crsent','crsnt','crssng','div','driv','drv','dvd','exp','expr','express','expw','extn','extnsn','forests','forg','freewy','frry','frt','frway','frwy','gardn','gatewy','gatway','grden','grdn','grdns','grov','gtway','harb','harbr','highwy','hills','hiway','hiwy','hllw','hls','hollows','holws','hrbor','ht','hway','isles','islnd','islnds','jction','jctn','jctns','junctn','juncton','knol','ldge','lf','lndng','loaf','lodg','loops','medows','missn','mnt','mntain','mntn','mntns','mountains','mountin','mssn','mtin','orchrd','ovl','parkwy','paths','pikes','pkway','pkwys','pky','plza','prk','prr','rad','radiel','ranches','rdge','rivr','rnchs','rvr','shoar','shoars','spng','spngs','sprng','sprngs','sqr','sqre','sqrs','squ','statn','stn','str','strav','straven','stravn','streme','strt','strvn','strvnue','sumitt','summit','terr','tpke','traces','tracks','trails','trk','trks','trlrs','trls','trnpk','tunel','tunls','tunnels','tunnl','unions','uns','vally','vdct','viadct','vill','villag','villg','villiage','vist','vlly','vst','vsta','wy'); public function remove_trailing_period($haystack){ if(substr($haystack, (strlen($haystack)-1)) == '.'){ $haystack = substr($haystack, 0, (strlen($haystack) - 1)); } return $haystack; } public function clean_street_address($haystack){ $haystack = str_replace(array("\n", "\r", "\t"), "", trim($haystack)); if(empty($haystack)){ return false; } $haystack = explode(' ', $haystack); if(!is_array($haystack) || ($haystack_length = count($haystack)) <= 0){ return false; } $haystack_suffix = $this->remove_trailing_period(strtolower($haystack[$haystack_length -1])); if(in_array($haystack_suffix, $this->street_names)){ array_pop($haystack); return implode(" ", $haystack); } return false; } }
Add a Comment