Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Dedicated server web hosting provided by Guru-host.eu.
format_address modifier plugin

 
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
jet-jock
Smarty Regular


Joined: 11 Sep 2003
Posts: 48
Location: Connecticut, USA

PostPosted: Tue Sep 06, 2005 12:25 am    Post subject: format_address modifier plugin Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP