<?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>Matt Lowden</title>
	<atom:link href="http://www.mattlowden.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mattlowden.com</link>
	<description></description>
	<lastBuildDate>Thu, 13 May 2010 12:58:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Recovering HTTP $_GET variables when using Apache&#8217;s mod_rewrite</title>
		<link>http://www.mattlowden.com/blog/2010/05/recovering-http-_get-variables-when-using-apaches-mod_rewrite/</link>
		<comments>http://www.mattlowden.com/blog/2010/05/recovering-http-_get-variables-when-using-apaches-mod_rewrite/#comments</comments>
		<pubDate>Thu, 13 May 2010 12:43:26 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.mattlowden.com/?p=101</guid>
		<description><![CDATA[Anyone using Apache&#8217;s mod_rewrite to handle HTTP requests will know that your $_GET variables  are no longer recognised by the server as the URI is treated as a single string value.
PHP has a function, called mb_parse_str(), that parses the query string representation of an array into a multi-dimensional array. This can be used to correctly [...]]]></description>
			<content:encoded><![CDATA[<p>Anyone using Apache&#8217;s <code>mod_rewrite</code> to handle HTTP requests will know that your <code>$_GET</code> variables  are no longer recognised by the server as the URI is treated as a single <code>string</code> value.</p>
<p>PHP has a function, called <code><a href="http://php.net/manual/en/function.mb-parse-str.php" target="_blank">mb_parse_str()</a></code>, that parses the query string representation of an <code>array</code> into a multi-dimensional <code>array</code>. This can be used to correctly represent the query string part of the URL.</p>
<p>The below function returns an <code>array</code> that holds the same values you&#8217;d expect from <code>$_GET</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_http_vars<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #990000;">parse_url</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> PHP_URL_QUERY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">mb_parse_str</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span> <span style="color: #000088;">$get</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$get</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>To use the function simply follow the example below;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$get</span> <span style="color: #339933;">=</span> get_http_vars<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mattlowden.com/blog/2010/05/recovering-http-_get-variables-when-using-apaches-mod_rewrite/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Deep merging two arrays in PHP</title>
		<link>http://www.mattlowden.com/blog/2010/02/deep-merging-two-arrays-in-php/</link>
		<comments>http://www.mattlowden.com/blog/2010/02/deep-merging-two-arrays-in-php/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 13:22:18 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.mattlowden.com/?p=93</guid>
		<description><![CDATA[PHP has a wealth of functions for manipulating arrays, however; I often want to deep merge 2 arrays whilst maintaining the key =&#62; value structure. PHP does have functions that will merge multiple arrays but they attempt to maintain duplicate keys.
The below function take 2 arguments (arrays). Arguments are in order of importance, the second [...]]]></description>
			<content:encoded><![CDATA[<p>PHP has a wealth of functions for manipulating arrays, however; I often want to deep merge 2 arrays whilst maintaining the key =&gt; value structure. PHP does have functions that will merge multiple arrays but they attempt to maintain duplicate keys.</p>
<p>The below function take 2 arguments (arrays). Arguments are in order of importance, the second arguments values will always overwrite the first arguments values and so on.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> array_merge_replace<span style="color: #009900;">&#40;</span><span style="color: #000088;">$base_array</span><span style="color: #339933;">,</span> <span style="color: #000088;">$merge_array</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$new_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$key_list</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span><span style="color: #000088;">$base_array</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span><span style="color: #000088;">$merge_array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key_list</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span><span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$base_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span>is_array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$merge_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$new_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> array_merge_replace<span style="color: #009900;">&#40;</span><span style="color: #000088;">$base_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$merge_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$new_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$merge_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span> ? <span style="color: #000088;">$merge_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$base_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$new_array</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mattlowden.com/blog/2010/02/deep-merging-two-arrays-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Removing null values from a PHP Array</title>
		<link>http://www.mattlowden.com/blog/2009/07/removing-null-values-in-a-php-array/</link>
		<comments>http://www.mattlowden.com/blog/2009/07/removing-null-values-in-a-php-array/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 12:00:58 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.mattlowden.com/?p=60</guid>
		<description><![CDATA[The following function will remove all null values from a PHP array. This is especially useful when exploding strings with a post/prefixed delimiter.

function array_remove_null&#40;&#38;amp;$array&#41;&#123;
	$new_array = array&#40;&#41;;
	foreach&#40;$array as $k=&#38;gt;$v&#41;&#123;
		if&#40;$v&#41; $new_array&#91;$k&#93;=$v;
	&#125;
	$array=$new_array;
&#125;

To use the function simply follow the example below;

array_remove_null&#40;$your_array_object&#41;;

]]></description>
			<content:encoded><![CDATA[<p>The following function will remove all <code>null</code> values from a PHP <code>array</code>. This is especially useful when exploding strings with a post/prefixed delimiter.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> array_remove_null<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$new_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span><span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$new_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$v</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$array</span><span style="color: #339933;">=</span><span style="color: #000088;">$new_array</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>To use the function simply follow the example below;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">array_remove_null<span style="color: #009900;">&#40;</span><span style="color: #000088;">$your_array_object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mattlowden.com/blog/2009/07/removing-null-values-in-a-php-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Auto-hide field prompt</title>
		<link>http://www.mattlowden.com/blog/2009/04/auto-hide-field-prompt/</link>
		<comments>http://www.mattlowden.com/blog/2009/04/auto-hide-field-prompt/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 21:34:47 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Forms]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.mattlowden.com/?p=20</guid>
		<description><![CDATA[Recently I&#8217;ve developed a couple of forms that prompt user input via the value of the field rather than a label. For instance, the text &#8220;Enter your name&#8221; within a field that requires you to enter your name.
Usually I want the text to disappear when the user focuses on the input or textarea element and [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve developed a couple of forms that prompt user input via the value of the field rather than a label. For instance, the text &#8220;Enter your name&#8221; within a field that requires you to enter your name.</p>
<p>Usually I want the text to disappear when the user focuses on the <code>input</code> or <code>textarea</code> element and reappear if the user moves away from the the element without inputting any text.</p>
<p>This function looks for all <code>input</code> and <code>textarea</code> elements with the class &#8220;hide-prompt&#8221;. Simply run this function after the DOM has loaded. Make sure that your <code>input</code> and <code>textarea</code> elements have unique ID&#8217;s.</p>
<h3>jQuery</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> _field_value_prompt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> field_list <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input.hide-prompt, textarea.hide-prompt'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> field_list_values <span style="color: #339933;">=</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> f<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> f <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> field_list.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>f<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		field_list_values<span style="color: #009900;">&#91;</span>$<span style="color: #009900;">&#40;</span>current_element<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>current_element<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span>field_list<span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> field_list_values<span style="color: #009900;">&#91;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span>field_list<span style="color: #009900;">&#41;</span>.<span style="color: #000066;">blur</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>field_list_values<span style="color: #009900;">&#91;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mattlowden.com/blog/2009/04/auto-hide-field-prompt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
