<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Eddie On Everything &#187; PHP</title>
	<atom:link href="http://www.eddieoneverything.com/category/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.eddieoneverything.com</link>
	<description>Tips &#38; tricks on things that interest me</description>
	<lastBuildDate>Wed, 11 Jan 2012 08:29:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP Programming: U.S. State list functions / State abbreviation to State name function</title>
		<link>http://www.eddieoneverything.com/programming/php-programming-us-state-list-functions-state-abbreviation-to-state-name-function.php</link>
		<comments>http://www.eddieoneverything.com/programming/php-programming-us-state-list-functions-state-abbreviation-to-state-name-function.php#comments</comments>
		<pubDate>Thu, 13 Nov 2008 02:13:09 +0000</pubDate>
		<dc:creator>eddie</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://www.eddieoneverything.com/programming/php-programming-us-state-list-functions-state-abbreviation-to-state-name-function.php</guid>
		<description><![CDATA[Here are a few PHP functions that I find useful for United States related things.  Nothing brilliant or groundbreaking &#8211; just something to save you some typing.
1. A PHP function for printing a state select box
2. A PHP function that returns the full state name when passed the abbreviation
3. A PHP snippet for printing [...]]]></description>
			<content:encoded><![CDATA[<p>Here are a few PHP functions that I find useful for United States related things.  Nothing brilliant or groundbreaking &#8211; just something to save you some typing.</p>
<p>1. A PHP function for printing a state select box<br />
2. A PHP function that returns the full state name when passed the abbreviation<br />
3. A PHP snippet for printing a state select box</p>
<p>This function prints a state select box.  It accepts the name of the box and the abbreviation of the state that you want selected.</p>
<pre name="code" class="php">
   function printStateSelectBox($name, $selected){
      $state_arr=array( "AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC",
         "DE", "FL", "GA", "HI", "IA", "ID", "IL", "IN", "KS", "KY", "LA",
         "MA", "MD", "ME", "MI", "MN", "MO", "MS", "MT", "NC", "ND", "NE",
         "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "RI", "SC",
         "SD", "TN", "TX", "UT", "VA", "VT", "WA", "WI", "WV", "WY");

      $ret="
<select name=\"$name\">";
      if (!$selected){
         $ret.="<option value=\"\" > </option>\n";
      }else{
         $ret.="<option value=\"\" selected=\"selected\"> </option>\n";
      }

      foreach ($state_arr as $state){
         if ($selected==$state){
            $ret.="<option value=\"$state\" selected=\"selected\">$state</option>\n";
         }else{
            $ret.="<option value=\"$state\">$state</option>\n";
         }
      }

      $ret.="</select>

";
      //print "selected is $selected";
      return ($ret);
   }
</pre>
<p>This function returns the state name when passed the abbreviation.</p>
<pre name="code" class="php">
 function getStateNameByAbbreviation($state){
      if ($state=="AK"){ return "Alaska"; }
      if ($state=="AL"){ return "Alabama"; }
      if ($state=="AR"){ return "Arkansas"; }
      if ($state=="AZ"){ return "Arizona"; }
      if ($state=="CA"){ return "California"; }
      if ($state=="CO"){ return "Colorado"; }
      if ($state=="CT"){ return "Connecticut"; }
      if ($state=="DC"){ return "District of Columbia"; }
      if ($state=="DE"){ return "Delaware"; }
      if ($state=="FL"){ return "Florida"; }
      if ($state=="GA"){ return "Georgia"; }
      if ($state=="HI"){ return "Hawaii"; }
      if ($state=="IA"){ return "Iowa"; }
      if ($state=="ID"){ return "Idaho"; }
      if ($state=="IL"){ return "Illinois"; }
      if ($state=="IN"){ return "Indiana"; }
      if ($state=="KS"){ return "Kansas"; }
      if ($state=="KY"){ return "Kentucky"; }
      if ($state=="LA"){ return "Louisiana"; }
        if ($state=="MA"){ return "Massachusetts"; }
        if ($state=="MD"){ return "Maryland"; }
        if ($state=="ME"){ return "Maine"; }
        if ($state=="MI"){ return "Michigan"; }
        if ($state=="MN"){ return "Minnesota"; }
        if ($state=="MO"){ return "Missouri"; }
        if ($state=="MS"){ return "Mississippi"; }
        if ($state=="MT"){ return "Montana"; }
        if ($state=="NC"){ return "North Carolina"; }
        if ($state=="ND"){ return "North Dakota"; }
        if ($state=="NE"){ return "Nebraska"; }
        if ($state=="NH"){ return "New Hampshire"; }
        if ($state=="NJ"){ return "New Jersey"; }
        if ($state=="NM"){ return "New Mexico"; }
        if ($state=="NV"){ return "Nevada"; }
        if ($state=="NY"){ return "New York"; }
        if ($state=="OH"){ return "Ohio"; }
        if ($state=="OK"){ return "Oklahoma"; }
        if ($state=="OR"){ return "Oregon"; }
        if ($state=="PA"){ return "Pennsylvania"; }
        if ($state=="RI"){ return "Rhode Island"; }
        if ($state=="SC"){ return "South Carolina"; }
        if ($state=="SD"){ return "South Dakota"; }
        if ($state=="TN"){ return "Tennessee"; }
        if ($state=="TX"){ return "Texas"; }
        if ($state=="UT"){ return "Utah"; }
        if ($state=="VA"){ return "Virginia"; }
        if ($state=="VT"){ return "Vermont"; }
        if ($state=="WA"){ return "Washington"; }
        if ($state=="WI"){ return "Wisconsin"; }
        if ($state=="WV"){ return "West Virginia"; }
      if ($state=="WY"){ return "Wyoming"; }

   }
</pre>
<p>Another snippet for printing a State select box.  </p>
<pre name="code" class="php">
$state_list = array('AL'=>"Alabama",  'AK'=>"Alaska",  'AZ'=>"Arizona",  'AR'=>"Arkansas", 'CA'=>"California",  'CO'=>"Colorado",  'CT'=>"Connecticut",  'DE'=>"Delaware",'DC'=>"District Of Columbia",  'FL'=>"Florida",  'GA'=>"Georgia",  'HI'=>"Hawaii", 'ID'=>"Idaho",  'IL'=>"Illinois",  'IN'=>"Indiana",  'IA'=>"Iowa",  'KS'=>"Kansas", 'KY'=>"Kentucky",  'LA'=>"Louisiana",  'ME'=>"Maine",  'MD'=>"Maryland", 'MA'=>"Massachusetts",  'MI'=>"Michigan",  'MN'=>"Minnesota",  'MS'=>"Mississippi", 'MO'=>"Missouri",  'MT'=>"Montana", 'NE'=>"Nebraska", 'NV'=>"Nevada", 'NH'=>"New Hampshire", 'NJ'=>"New Jersey", 'NM'=>"New Mexico", 'NY'=>"New York", 'NC'=>"North Carolina", 'ND'=>"North Dakota", 'OH'=>"Ohio",  'OK'=>"Oklahoma",  'OR'=>"Oregon",'PA'=>"Pennsylvania",  'RI'=>"Rhode Island",  'SC'=>"South Carolina",  'SD'=>"South Dakota", 'TN'=>"Tennessee",  'TX'=>"Texas",  'UT'=>"Utah",  'VT'=>"Vermont",  'VA'=>"Virginia", 'WA'=>"Washington",  'WV'=>"West Virginia",  'WI'=>"Wisconsin",  'WY'=>"Wyoming");

foreach ($state_list as $k=>$v){
   if ($k == $select){
      $sv=" SELECTED ";
   }else{
      $sv="";
   }
   print " <option value=\"$k\" $sv>$k</option>";
}
</pre>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.eddieoneverything.com/programming/getting-phps-print_r-function-to-return-a-string.php" title="Getting PHP&#8217;s print_r Function To Return A String">Getting PHP&#8217;s print_r Function To Return A String</a></li><li><a href="http://www.eddieoneverything.com/articles/validating-an-email-address-with-phps-filter_var-isnt-perfect.php" title="Validating an Email Address with PHP&rsquo;s filter_var isn&rsquo;t perfect">Validating an Email Address with PHP&rsquo;s filter_var isn&rsquo;t perfect</a></li><li><a href="http://www.eddieoneverything.com/articles/how-to-scan-a-computer-for-open-ports.php" title="How to Scan a Computer for Open Ports">How to Scan a Computer for Open Ports</a></li><li><a href="http://www.eddieoneverything.com/articles/the-zen-of-taco-bell-programming-using-unix-tools-to-prevent-reinventing-the-wheel.php" title="The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel">The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel</a></li><li><a href="http://www.eddieoneverything.com/articles/how-to-make-phpbb3-forum-links-automatically-relnofollow.php" title="How to Make phpbb3 Forum Links Automatically rel=&#8221;nofollow&#8221;">How to Make phpbb3 Forum Links Automatically rel=&#8221;nofollow&#8221;</a></li><li><a href="http://www.eddieoneverything.com/programming/how-to-use-global-variables-from-another-file-in-a-perl-module-or-package.php" title="How To Use Global Variables From Another File In A Perl Module or Package">How To Use Global Variables From Another File In A Perl Module or Package</a></li><li><a href="http://www.eddieoneverything.com/articles/optimizing-the-google-syntax-highlighter-wordpress-plugin-even-further.php" title="Optimizing the Google Syntax Highlighter Wordpress Plugin Even Further">Optimizing the Google Syntax Highlighter Wordpress Plugin Even Further</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.eddieoneverything.com/programming/php-programming-us-state-list-functions-state-abbreviation-to-state-name-function.php/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

