Posted By

jwwest on 01/08/11


Tagged


Versions (?)

Convert state name to abbreviation


 / Published in: PHP
 

  1. function convert_state_to_abbreviation($state_name) {
  2. switch ($state_name) {
  3. case "Alabama":
  4. return "AL";
  5. break;
  6. case "Alaska":
  7. return "AK";
  8. break;
  9. case "Arizona":
  10. return "AZ";
  11. break;
  12. case "Arkansas":
  13. return "AR";
  14. break;
  15. case "California":
  16. return "CA";
  17. break;
  18. case "Colorado":
  19. return "CO";
  20. break;
  21. case "Connecticut":
  22. return "CT";
  23. break;
  24. case "Delaware":
  25. return "DE";
  26. break;
  27. case "Florida":
  28. return "FL";
  29. break;
  30. case "Georgia":
  31. return "GA";
  32. break;
  33. case "Hawaii":
  34. return "HI";
  35. break;
  36. case "Idaho":
  37. return "ID";
  38. break;
  39. case "Illinois":
  40. return "IL";
  41. break;
  42. case "Indiana":
  43. return "IN";
  44. break;
  45. case "Iowa":
  46. return "IA";
  47. break;
  48. case "Kansas":
  49. return "KS";
  50. break;
  51. case "Kentucky":
  52. return "KY";
  53. break;
  54. case "Louisana":
  55. return "LA";
  56. break;
  57. case "Maine":
  58. return "ME";
  59. break;
  60. case "Maryland":
  61. return "MD";
  62. break;
  63. case "Massachusetts":
  64. return "MA";
  65. break;
  66. case "Michigan":
  67. return "MI";
  68. break;
  69. case "Minnesota":
  70. return "MN";
  71. break;
  72. case "Mississippi":
  73. return "MS";
  74. break;
  75. case "Missouri":
  76. return "MO";
  77. break;
  78. case "Montana":
  79. return "MT";
  80. break;
  81. case "Nebraska":
  82. return "NE";
  83. break;
  84. case "Nevada":
  85. return "NV";
  86. break;
  87. case "New Hampshire":
  88. return "NH";
  89. break;
  90. case "New Jersey":
  91. return "NJ";
  92. break;
  93. case "New Mexico":
  94. return "NM";
  95. break;
  96. case "New York":
  97. return "NY";
  98. break;
  99. case "North Carolina":
  100. return "NC";
  101. break;
  102. case "North Dakota":
  103. return "ND";
  104. break;
  105. case "Ohio":
  106. return "OH";
  107. break;
  108. case "Oklahoma":
  109. return "OK";
  110. break;
  111. case "Oregon":
  112. return "OR";
  113. break;
  114. case "Pennsylvania":
  115. return "PA";
  116. break;
  117. case "Rhode Island":
  118. return "RI";
  119. break;
  120. case "South Carolina":
  121. return "SC";
  122. break;
  123. case "South Dakota":
  124. return "SD";
  125. break;
  126. case "Tennessee":
  127. return "TN";
  128. break;
  129. case "Texas":
  130. return "TX";
  131. break;
  132. case "Utah":
  133. return "UT";
  134. break;
  135. case "Vermont":
  136. return "VT";
  137. break;
  138. case "Virginia":
  139. return "VA";
  140. break;
  141. case "Washington":
  142. return "WA";
  143. break;
  144. case "Washington D.C.":
  145. return "DC";
  146. break;
  147. case "West Virginia":
  148. return "WV";
  149. break;
  150. case "Wisconsin":
  151. return "WI";
  152. break;
  153. case "Wyoming":
  154. return "WY";
  155. break;
  156. case "Alberta":
  157. return "AB";
  158. break;
  159. case "British Columbia":
  160. return "BC";
  161. break;
  162. case "Manitoba":
  163. return "MB";
  164. break;
  165. case "New Brunswick":
  166. return "NB";
  167. break;
  168. case "Newfoundland & Labrador":
  169. return "NL";
  170. break;
  171. case "Northwest Territories":
  172. return "NT";
  173. break;
  174. case "Nova Scotia":
  175. return "NS";
  176. break;
  177. case "Nunavut":
  178. return "NU";
  179. break;
  180. case "Ontario":
  181. return "ON";
  182. break;
  183. case "Prince Edward Island":
  184. return "PE";
  185. break;
  186. case "Quebec":
  187. return "QC";
  188. break;
  189. case "Saskatchewan":
  190. return "SK";
  191. break;
  192. case "Yukon Territory":
  193. return "YT";
  194. break;
  195. default:
  196. return $state_name;
  197. }
  198. }

Report this snippet  

You need to login to post a comment.