|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
jet-jock Smarty Regular
Joined: 11 Sep 2003 Posts: 48 Location: Connecticut, USA
|
Posted: Tue Sep 06, 2005 12:25 am Post subject: format_address modifier plugin |
|
|
Code for cleaning up common U.S. addresses prior to DB insertion.
$_val is an address string.
e.g. '21325 nE fAirfIELD Ln.' => '21325 NE Fairfield Lane'
My regexp skills are not that great...any suggestions/additions welcome.
[php:1:f9d161e3e0]
function smarty_modifier_format_address($_val) {
$_my_array = explode(" ", strtolower($_val));
while (list($_k,$_v)=each($_my_array))
{
//directional abbreviations
//N
if (preg_match("/^n[\.]?$/i",$_v))
{
$_my_array[$_k] = "N";
}
//NE
if (preg_match("/^ne[\.]?$/i",$_v))
{
$_my_array[$_k] = "NE";
}
//E
if (preg_match("/^e[\.]?$/i",$_v))
{
$_my_array[$_k] = "E";
}
//SE
if (preg_match("/^se[\.]?$/i",$_v))
{
$_my_array[$_k] = "SE";
}
//S
if (preg_match("/^s[\.]?$/i",$_v))
{
$_my_array[$_k] = "S";
}
//SW
if (preg_match("/^sw[\.]?$/i",$_v))
{
$_my_array[$_k] = "SW";
}
//W
if (preg_match("/^w[\.]?$/i",$_v))
{
$_my_array[$_k] = "W";
}
//NW
if (preg_match("/^nw[\.]?$/i",$_v))
{
$_my_array[$_k] = "NW";
}
//street abbreviations
//street
if (preg_match("/^st[r]?[\.]?$/i",$_v))
{
$_my_array[$_k] = "street";
}
//lane
if (preg_match("/^ln[\.]?$/i",$_v))
{
$_my_array[$_k] = "lane";
}
//road
if (preg_match("/^rd[\.]?$/i",$_v))
{
$_my_array[$_k] = "road";
}
//way
if (preg_match("/^wy[\.]?$/i",$_v))
{
$_my_array[$_k] = "way";
}
//court
if (preg_match("/^ct[\.]?$/i",$_v))
{
$_my_array[$_k] = "court";
}
}
$_val = ucwords(implode(" ", $_my_array));
return $_val;
}
[/php:1:f9d161e3e0]
Cheers.
jet-jock |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|