<?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>Tiffany B. Brown &#187; drop down menu</title>
	<atom:link href="http://tiffanybbrown.com/tag/drop-down-menu/feed/" rel="self" type="application/rss+xml" />
	<link>http://tiffanybbrown.com</link>
	<description>A web log about web development and internet culture with frequent detours into other stuff.</description>
	<lastBuildDate>Fri, 10 Feb 2012 23:35:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Turn text files into pull down menus</title>
		<link>http://tiffanybbrown.com/2008/02/26/turn-text-files-into-pull-down-menus/</link>
		<comments>http://tiffanybbrown.com/2008/02/26/turn-text-files-into-pull-down-menus/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 02:16:43 +0000</pubDate>
		<dc:creator>tiffany</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[drop down menu]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[pull down menu]]></category>

		<guid isPermaLink="false">http://tiffanybbrown.com/2008/02/26/turn-text-files-into-pull-down-menus/</guid>
		<description><![CDATA[UPDATE: This could also be done with the foreach() construct, but here &#8212; on my set-up at least &#8212; the for loop is a teensy bit faster. I developed this PHP function for a project I&#8217;m working on. I&#8217;m posting it here in case I need it again, or in case you find it handy. [...]]]></description>
			<content:encoded><![CDATA[<p class="editors-note"><b>UPDATE:</b> This could also be done with the <code>foreach()</code> construct, but here &#8212; on my set-up at least &#8212; the <code>for</code> loop is a teensy bit faster.</p>
<p>I developed this PHP function for a project I&#8217;m working on. I&#8217;m posting it here in case I need it again, or in case you find it handy.</p>
<pre>
#Input text files must contain one item per line
function print_menu($txtfile_or_files){
	$args = func_get_args();
	$num_args = func_num_args();
	$input = array();

	for($i = 0; $i &lt; $num_args; $i++){
		// get contents of each text file specified
		$lines = file($args[$i]); 

		// get each line from each file an add to array
		for($j = 0; $j &lt; count($lines); $j++){
			array_push($input,$lines[$j]);
		}
	}
	// sort alphabetically
	sort($input,SORT_STRING);		

	for($i = 0; $i &lt; count($input); $i++){
		$value = str_replace(' ','_',strtolower(trim($input[$i])));
		echo '&lt;option value="'.$value.'"&gt;'.trim($input[$i])."&lt;/option&gt;\n";
	}
}
</pre>
<h3>Configuration and use</h3>
<p>The variable <code>$txtfile_or_files</code> should be a comma-separated list of paths to plain text files. This function accepts multiple arguments, in case you want to string multiple files into one menu.</p>
<p>Each text file should contain one item per line. For example:</p>
<pre>
Red
Blue
Orange
Green
</pre>
<p>Add another line or two of code if you need to indicate whether the form field value has already been selected.</p>
]]></content:encoded>
			<wfw:commentRss>http://tiffanybbrown.com/2008/02/26/turn-text-files-into-pull-down-menus/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

