Convert long State names to 2 letter codes

Public

Convert long written state names to addressfield 2 digit character codes for location Migrate. This switch statement is very fast amd ready to go!

Get raw version
php
  1. /**
  2.   * Here we convert states into two digit state codes for the database.
  3.   */
  4. switch ($row->profile_state) {
  5.  
  6. case 'Alabama':
  7. $row->profile_state = 'AL';
  8. break;
  9.  
  10. case 'Alaska':
  11. $row->profile_state = 'AK';
  12. break;
  13.  
  14. case 'Arizona':
  15. $row->profile_state = 'AZ';
  16. break;
  17.  
  18. case 'Arkansas':
  19. $row->profile_state = 'AR';
  20. break;
  21.  
  22. case 'California':
  23. $row->profile_state = 'CA';
  24. break;
  25.  
  26. case 'Colorado':
  27. $row->profile_state = 'CO';
  28. break;
  29.  
  30. case 'Connecticut':
  31. $row->profile_state = 'CT';
  32. break;
  33.  
  34. case 'Delaware':
  35. $row->profile_state = 'DE';
  36. break;
  37.  
  38. case 'Florida':
  39. $row->profile_state = 'FL';
  40. break;
  41.  
  42. case 'Georgia':
  43. $row->profile_state = 'GA';
  44. break;
  45.  
  46. case 'Hawaii':
  47. $row->profile_state = 'HI';
  48. break;
  49.  
  50. case 'Idaho':
  51. $row->profile_state = 'ID';
  52. break;
  53.  
  54. case 'Illinois':
  55. $row->profile_state = 'IL';
  56. break;
  57.  
  58. case 'Indiana':
  59. $row->profile_state = 'IN';
  60. break;
  61.  
  62. case 'Iowa':
  63. $row->profile_state = 'IA';
  64. break;
  65.  
  66. case 'Kansas':
  67. $row->profile_state = 'KS';
  68. break;
  69.  
  70. case 'Kentucky':
  71. $row->profile_state = 'KY';
  72. break;
  73.  
  74. case 'Louisiana':
  75. $row->profile_state = 'LA';
  76. break;
  77.  
  78. case 'Maine':
  79. $row->profile_state = 'ME';
  80. break;
  81.  
  82. case 'Maryland':
  83. $row->profile_state = 'MD';
  84. break;
  85.  
  86. case 'Massachusetts':
  87. $row->profile_state = 'MA';
  88. break;
  89.  
  90. case 'Michigan':
  91. $row->profile_state = 'MI';
  92. break;
  93.  
  94. case 'Minnesota':
  95. $row->profile_state = 'MN';
  96. break;
  97.  
  98. case 'Mississippi':
  99. $row->profile_state = 'MS';
  100. break;
  101.  
  102. case 'Missouri':
  103. $row->profile_state = 'MO';
  104. break;
  105.  
  106. case 'Montana':
  107. $row->profile_state = 'MT';
  108. break;
  109.  
  110. case 'Nebraska':
  111. $row->profile_state = 'NE';
  112. break;
  113.  
  114. case 'Nevada':
  115. $row->profile_state = 'NV';
  116. break;
  117.  
  118. case 'New Hampshire':
  119. $row->profile_state = 'NH';
  120. break;
  121.  
  122. case 'New Jersey':
  123. $row->profile_state = 'NJ';
  124. break;
  125.  
  126. case 'New Mexico':
  127. $row->profile_state = 'NM';
  128. break;
  129.  
  130. case 'New York':
  131. $row->profile_state = 'NY';
  132. break;
  133.  
  134. case 'North Carolina':
  135. $row->profile_state = 'NC';
  136. break;
  137.  
  138. case 'North Dakota':
  139. $row->profile_state = 'ND';
  140. break;
  141.  
  142. case 'Ohio':
  143. $row->profile_state = 'OH';
  144. break;
  145.  
  146. case 'Oklahoma':
  147. $row->profile_state = 'OK';
  148. break;
  149.  
  150. case 'Oregon':
  151. $row->profile_state = 'OR';
  152. break;
  153.  
  154. case 'Pennsylvania':
  155. $row->profile_state = 'PA';
  156. break;
  157.  
  158. case 'Rhode Island':
  159. $row->profile_state = 'RI';
  160. break;
  161.  
  162. case 'South Carolina':
  163. $row->profile_state = 'SC';
  164. break;
  165.  
  166. case 'South Dakota':
  167. $row->profile_state = 'SD';
  168. break;
  169.  
  170. case 'Tennessee':
  171. $row->profile_state = 'TN';
  172. break;
  173.  
  174. case 'Texas':
  175. $row->profile_state = 'TX';
  176. break;
  177.  
  178. case 'Utah':
  179. $row->profile_state = 'UT';
  180. break;
  181.  
  182. case 'Vermont':
  183. $row->profile_state = 'VT';
  184. break;
  185.  
  186. case 'Virginia':
  187. $row->profile_state = 'VA';
  188. break;
  189.  
  190. case 'Washington':
  191. $row->profile_state = 'WA';
  192. break;
  193.  
  194. case 'West Virginia':
  195. $row->profile_state = 'WV';
  196. break;
  197.  
  198. case 'Wisconsin':
  199. $row->profile_state = 'WI';
  200. break;
  201.  
  202. case 'Wyoming':
  203. $row->profile_state = 'WY';
  204. break;
  205.  
  206. case 'Washington DC':
  207. $row->profile_state = 'DC';
  208. break;
  209.  
  210. case 'Puerto Rico':
  211. $row->profile_state = 'PR';
  212. break;
  213.  
  214. case 'U.S. Virgin Islands':
  215. $row->profile_state = 'VI';
  216. break;
  217.  
  218. case 'American Samoa':
  219. $row->profile_state = 'AS';
  220. break;
  221.  
  222. case 'Guam':
  223. $row->profile_state = 'GU';
  224. break;
  225.  
  226. case 'Northern Mariana Islands':
  227. $row->profile_state = 'MP';
  228. break;
  229.  
  230. /**
  231.   * We do not set a default case, here, and instead just import the long text field to be inserted into state/province field.
  232.   */
  233.  
  234. break;
  235. }