Here is the list; I'm doing this to "normalize" a data set of addresses for easier look-ups.
I've tried using strtr() and str_ireplace() but it doesn't work out well. Here is a shorter set of the list for testing.
<?php
function street_abbreviations_regex($input) {
$list = array(
' ave' => ' avenue',
' blvd' => ' boulevard',
' cir' => ' circle',
' ct' => ' court',
' expy' => ' expressway',
' fwy' => ' freeway',
' ln' => ' lane',
' pky' => ' parkway',
' rd' => ' road',
' sq' => ' square',
' st' => ' street',
' tpke' => ' turnpike',
' n' => ' north',
' e' => ' east',
' s' => ' south',
' w' => ' west',
' ne' => ' northeast',
' se' => ' southeast',
' sw' => ' southwest',
' nw' => ' northwest',
);
// $input = strtr(strtolower($input), $list);
$input = str_ireplace(array_keys($list), array_values($list), strtolower($input));
$regex_street = (preg_replace("/[^A-Za-z0-9]/", "", $input));
return $regex_street;
?>
Input
echo street_abbreviations_regex('10 E Union St.') . " <br>\n";
echo street_abbreviations_regex('10 E Union Street') . " <br>\n";
Output from strtr()
10eastunionsoutht
10eastunionsouthtreet
Output from str_ireplace()
10eastunionsouthtreet
10eastunionsouthtreetreet