I think the easiest way to parse this would be to use explode.
Say your field name is "location." Then say you did a mysql_fetch_array (or used whater db abstraction you prefer) and got a row as an array.
So now, $row[location] equals "Washington, DC 20217-0002"
Now do the following:
// explode the location string into an array
$location = explode(" ", $row[location]);
// the first part is the city, but get rid of the trailing comma
$city = str_replace(",$", "", $location[0]);
//the second part is the state
$state = $location[1];
//the last part is the zip
$zip = $location[2];
If you're looping through an array of rows, you'll want to do:
$i = 0;
while ($row = mysql_fetch_array($result)) {
$location = explode(" ", $row[location]);
$state[$i] = $location[1];
print $state[$i];
// do whatever you want with $state[$i]
}
Then you have an array of all the states.