Simple one-trick-pony PHP function to take a state name (case insensitive) and return the 2 letter abbreviation.
function state_to_twoletter( $state_name ) {
$state = array();
$state['ALABAMA']='AL';
$state['ALASKA']='AK';
$state['AMERICAN SAMOA']='AS';
$state['ARIZONA']='AZ';
$state['ARKANSAS']='AR';
$state['CALIFORNIA']='CA';
$state['COLORADO']='CO';
$state['CONNECTICUT']='CT';
$state['DELAWARE']='DE';
$state['DISTRICT OF COLUMBIA']='DC';
$state['FEDERATED STATES OF MICRONESIA']='FM';
$state['FLORIDA']='FL';
$state['GEORGIA']='GA';
$state['GUAM']='GU';
$state['HAWAII']='HI';
$state['IDAHO']='ID';
$state['ILLINOIS']='IL';
$state['INDIANA']='IN';
$state['IOWA']='IA';
$state['KANSAS']='KS';
$state['KENTUCKY']='KY';
$state['LOUISIANA']='LA';
$state['MAINE']='ME';
$state['MARSHALL ISLANDS']='MH';
$state['MARYLAND']='MD';
$state['MASSACHUSETTS']='MA';
$state['MICHIGAN']='MI';
$state['MINNESOTA']='MN';
$state['MISSISSIPPI']='MS';
$state['MISSOURI']='MO';
$state['MONTANA']='MT';
$state['NEBRASKA']='NE';
$state['NEVADA']='NV';
$state['NEW HAMPSHIRE']='NH';
$state['NEW JERSEY']='NJ';
$state['NEW MEXICO']='NM';
$state['NEW YORK']='NY';
$state['NORTH CAROLINA']='NC';
$state['NORTH DAKOTA']='ND';
$state['NORTHERN MARIANA ISLANDS']='MP';
$state['OHIO']='OH';
$state['OKLAHOMA']='OK';
$state['OREGON']='OR';
$state['PALAU']='PW';
$state['PENNSYLVANIA']='PA';
$state['PUERTO RICO']='PR';
$state['RHODE ISLAND']='RI';
$state['SOUTH CAROLINA']='SC';
$state['SOUTH DAKOTA']='SD';
$state['TENNESSEE']='TN';
$state['TEXAS']='TX';
$state['UTAH']='UT';
$state['VERMONT']='VT';
$state['VIRGIN ISLANDS']='VI';
$state['VIRGINIA']='VA';
$state['WASHINGTON']='WA';
$state['WEST VIRGINIA']='WV';
$state['WISCONSIN']='WI';
$state['WYOMING']='WY';
return $state[strtoupper( $state_name )];
}