Thanks everyone, here's the final work of art?
| From: | Asendorf, John | Date: | Fri, 25 Aug 2000 13:56:34 +0000 |
| Subject: | Thanks everyone, here's the final work of art? | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-2146@lists.php.net to get a copy of this message | ||
Well, this isn't a question. Just the results of all the help I've gotten
over the past week. Thanks to everyone who helped, particularly CodeDuck!
You can see it in testing form at:
It breaks down an address so that the database I'm forced to work with will
be able to find it...
http://www.lcounty.com/boe/database/newtestform.php
****** You'll need an address from this file:
http://www.lcounty.com/boe/database/odbtest.php
Thanks again, the code (- the SQL) is below:
/* Address Parser 1.0
Started 08-21-2000
John P. Asendorf (jasendorf@lcounty.com)
Web Applications Developer
Licking County, Ohio - Information Systems
---------
NOTES:
$address comes from a form
*/
//convert the address to all upper case, might as well, database is that way
$address = strtoupper($address);
//establish a variable for the final street name to be used in the SQL
statement
$street = "";
//separate all of the pieces from $address
$piece = explode ( " " , $address );
//count the number of pieces
$num_pieces = sizeof ( $piece );
//PIECE 0 should be a number, so pass it to it's own variable that we can
check
//what if it's not a number? kick it back.
if (eregi ( "(^[0-9]{1,})" , $piece[0] )) {
$street_number = $piece[0]; //assign the variable something I
can understand
}
else {
die ("You must supply a street number. Please press your browser's
BACK button.");
}
//PIECE 1 could be a directional, street name, mt, or ordinal street (1st,
30th)
//no PIECE 1? kick it back
if ($piece[1] == "") {
die ("You must enter a street name. Please press your browser's
BACK button and enter a street name.");
}
//let's make a function to handle each of the words, no reason to make this
too hard
function test_for_special ($num) {
//some global values so that this works OK
global $street;
global $address_counter;
//check to see if it's an ordinal street name with regex first
//too intense to do a switch for every ordinal
if ( eregi("([0-9]{1,2}[a-zA-Z]{1,2})",$num) ) {
switch ($num) {
case "1ST":
$street .= "FIRST";
break;
case "2ND":
$street .= "SECOND";
break;
case "3RD":
$street .= "THIRD";
break;
case "4TH":
$street .= "FOURTH";
break;
case "5TH":
$street .= "FIFTH";
break;
case "6TH":
$street .= "SIXTH";
break;
case "7TH":
$street .= "SEVENTH";
break;
case "8TH":
$street .= "EIGHTH";
break;
case "9TH":
$street .= "NINTH";
break;
case "10TH":
$street .= "TENTH";
break;
case "11TH":
$street .= "ELEVENTH";
break;
case "12TH":
$street .= "TWELVETH";
break;
case "13TH":
$street .= "THIRTEENTH";
break;
case "14TH":
$street .= "FOURTEENTH";
break;
case "15TH":
$street .= "FIFTEENTH";
break;
case "16TH":
$street .= "SIXTEENTH";
break;
case "17TH":
$street .= "SEVENTEENTH";
break;
case "18TH":
$street .= "EIGHTEENTH";
break;
case "19TH":
$street .= "NINETEENTH";
break;
case "20TH":
$street .= "TWENTIETH";
break;
case "21ST":
$street .= "TWENTY FIRST";
break;
case "22ND":
$street .= "TWENTY SECOND";
break;
case "23RD":
$street .= "TWENTY THIRD";
break;
case "24TH":
$street .= "TWENTY FOURTH";
break;
case "25TH":
$street .= "TWENTY FIFTH";
break;
case "26TH":
$street .= "TWENTY SIXTH";
break;
case "27TH":
$street .= "TWENTY SEVENTH";
break;
case "28TH":
$street .= "TWENTY EIGTH";
break;
case "29TH":
$street .= "TWENTY NINTH";
break;
case "30TH":
$street .= "THIRTIETH";
break;
case "31ST":
$street .= "THIRTY FIRST";
break;
case "32ND":
$street .= "THIRTY SECOND";
break;
case "33RD":
$street .= "THIRTY THIRD";
break;
case "34TH":
$street .= "THIRTY FOURTH";
break;
case "35TH":
$street .= "THIRTY FIFTH";
break;
case "36TH":
$street .= "THIRTY SIXTH";
break;
case "37TH":
$street .= "THIRTY SEVENTH";
break;
case "38TH":
$street .= "THIRTY EIGHTH";
break;
case "39TH":
$street .= "THIRTY NINTH";
break;
case "40TH":
$street .= "FORTIETH";
break;
}
}
//not an ordinal? check to see if it's a special word
//use wildcards in case word is spelled out
else {
switch ($num) {
case "NORTH":
$street .= "N%";
break;
case "SOUTH":
$street .= "S%";
break;
case "EAST":
$street .= "E%";
break;
case "WEST":
$street .= "W%";
break;
case "SOUTHWEST":
$street .= "SW%";
break;
case "SOUTHEAST":
$street .= "SE%";
break;
case "NORTHWEST":
$street .= "NW%";
break;
case "NORTHEAST":
$street .= "NE%";
break;
case "MOUNT":
$street .= "MT%";
break;
case "STREET":
$street .= "ST%";
break;
case "ROAD":
$street .= "RD"; //too bad if road is spelled out
break;
case "AVENUE":
$street .= "AVE%";
break;
case "COURT":
$street .= "CT";
break;
case "DRIVE":
$street .= "DR%";
break;
case "PLACE":
$street .= "PL%";
break;
case "CIRCLE":
$street .= "CIR%";
break;
case "BOULEVARD":
$street .= "BLVD";
break;
case "APARTMENT":
$street .= "APT";
break;
case "LANE":
$street .= "LN";
break;
case "PARKWAY":
$street .= "PKWY";
break;
case "TRAIL":
$street .= "TRL";
break;
default:
$street .= $num;
break;
}
}
if ($address_counter != 1 ) {
$street .= " ";
}
}
//create a loop to spit out the name (almost done)
//skip the number
$address_counter = $num_pieces;
$skip_me = $num_pieces;
while ( list($key, $val) = each($piece) ) {
if ( $address_counter == $skip_me ) {
}
else {
test_for_special ($val);
}
$address_counter--;
if ( $address_counter==0 )
break;
}
//END OF ADDRESS PARSER
---------------------
John Asendorf - jasendorf@lcounty.com
Web Applications Developer - http://www.lcounty.com
Licking County, Ohio, USA
740-349-3631
>