<?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>FettesPS &#187; PHP</title>
	<atom:link href="http://www.fettesps.com/category/programming/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fettesps.com</link>
	<description>Fettes Programming Solutions</description>
	<lastBuildDate>Sun, 22 Jan 2012 18:21:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Ajax &#8211; Post Multiple Select Values</title>
		<link>http://www.fettesps.com/ajax-post-multiple-select-values/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ajax-post-multiple-select-values</link>
		<comments>http://www.fettesps.com/ajax-post-multiple-select-values/#comments</comments>
		<pubDate>Tue, 04 Oct 2011 11:12:41 +0000</pubDate>
		<dc:creator>FettesPS</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[AJAX]]></category>

		<guid isPermaLink="false">http://www.fettesps.com/?p=1557</guid>
		<description><![CDATA[So this form is pretty basic, it has a select box (list box) filled with possible values. You can select all or some of the values and then submit it to the server via Ajax. The problem was when I grabbed the value from the select box I only got the last value selected, not [...]]]></description>
			<content:encoded><![CDATA[<p>So this form is pretty basic, it has a select box (list box) filled with possible values.  You can select all or some of the values and then submit it to the server via Ajax.  The problem was when I grabbed the value from the select box I only got the last value selected, not each. Regardless of if I was using POST or GET I still had to build the parameter list since that&#8217;s how XMLHttpRequest works.  So I looped through the list and tried using the same parameter name for each, then on the PHP end I had the same result &#8212; each parameter overwrote the previous one and I saw only the last result. It wasn&#8217;t until I stumbled upon <a href="http://forums.devshed.com/javascript-development-115/ajax-posting-a-form-with-multiple-values-an-array-for-the-535164.html">this post</a> that someone gave a decent suggestion, which was to put a [] at the end of each parameter name when building the query string and PHP would automatically interpret it as an array. Since his code was somewhat over complicated I thought I&#8217;d share my version of it:</p>
<p><strong>test-utility.php</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Test Utility&lt;/title&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;test-utility.js&quot;&gt;	&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;h1 align='center'&gt;Test Utility&lt;/h1&gt;

&lt;center&gt;

    &lt;p style=&quot;width:450px; text-align:justify;&lt;?php if($error) echo &quot;color:red;&quot; ?&gt;&quot;&gt;
        &lt;?php if($error) { ?&gt;
            &lt;strong&gt;Error:&lt;/strong&gt; &lt;?php echo $error; ?&gt;
        &lt;?php } ?&gt;
    &lt;/p&gt;

    &lt;form name='frmTestUtility' id='frmTestUtility' method='post' action=''&gt;
    &lt;table cellpadding=&quot;2&quot; cellspacing=&quot;2&quot; border=&quot;0&quot;&gt;
    &lt;tr&gt;
        &lt;td&gt;
            Listbox(s):&lt;br&gt;&lt;br&gt;
            &lt;div style=&quot;font-size:smaller&quot;&gt;(Hold CTRL to&lt;br&gt;select multiple)&lt;/div&gt;
        &lt;/td&gt;
        &lt;td align=&quot;center&quot;&gt;
            &lt;select name='listbox[]' id='listbox' multiple=&quot;multiple&quot;&gt;
                &lt;option value='123'&gt;123&lt;/option&gt;
                &lt;option value='abc'&gt;abc&lt;/option&gt;
                &lt;option value='alpha'&gt;alpha&lt;/option&gt;
                &lt;option value='beta'&gt;beta&lt;/option&gt;
                &lt;option value='gamma'&gt;gamma&lt;/option&gt;
            &lt;/select&gt;
            &lt;br&gt;
            &lt;input type=&quot;button&quot; name=&quot;all&quot; value=&quot;All&quot; onClick='javascript:select_all();'&gt;
            &lt;input type=&quot;button&quot; name=&quot;none&quot; value=&quot;None&quot; onClick='javascript:select_none();'&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td colspan=&quot;2&quot;&gt;
            &lt;input type=&quot;button&quot; name=&quot;submit&quot; onclick=&quot;javascript:run_queries();&quot; value=&quot;Run SQL&quot; /&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
    &lt;/table&gt;
    &lt;/form&gt;

    &lt;div id=&quot;ajax_results&quot;&gt;
        &amp;nbsp;
    &lt;/div&gt;
    &lt;/center&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p><strong>test-utility.js</strong></p>
<pre class="brush: jscript; title: ; notranslate">
function select_all() {
    var d = document.getElementById(&quot;listbox&quot;);
        for(var i=0;i&lt;d.length;i++) {
            d.options[i].selected = &quot;1&quot;;
        }
}

function select_none() {
    var d = document.getElementById(&quot;listbox&quot;);

    for(var i=0;i&lt;d.length;i++) {
        d.options[i].selected = &quot;&quot;;
    }
}

// Build the query string and submit it to the next page for processing
function run_queries() {
    var xmlhttp, url;&lt;/pre&gt;

    // For modern browsers
    if(window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();

    // for IE 5/6
    } else {
        xmlhttp = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
    }

    //  Rebuild the array of selected option boxes
    lb = document.getElementById(&quot;listbox&quot;);
    for(var i=0; i &lt; lb.length; i++) {
        if(lb[i].selected) {
            // Note the [] after the name
            url += &quot;&amp;lb[]=&quot; + lb[i].value;
        }
    }

    xmlhttp.open(&quot;GET&quot;,&quot;test-utility-ajax.php&quot; + url, false);
    xmlhttp.send();

    if (xmlhttp.status == 200) {
        document.getElementById(&quot;ajax_results&quot;).innerHTML = xmlhttp.responseText;
    } else {
        return false;
    }

    return false;
}
</pre>
<p><strong>test-utility-ajax.php</strong>br></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
  // As you can see PHP displays it as an array
  if($_POST} print_r($_POST);
?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fettesps.com/ajax-post-multiple-select-values/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Converting an Array to JSON</title>
		<link>http://www.fettesps.com/php-converting-an-array-to-json/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-converting-an-array-to-json</link>
		<comments>http://www.fettesps.com/php-converting-an-array-to-json/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 13:09:01 +0000</pubDate>
		<dc:creator>FettesPS</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://www.fettesps.com/?p=875</guid>
		<description><![CDATA[Every now and then I stumble upon a tidbit of information that just makes me want to kick myself. Today was one of those days. Just by chance I ended up at an entry on PHP.net while Googling another issue. Once I realized what this function was capable of I was torn between thinking &#8220;Wow, [...]]]></description>
			<content:encoded><![CDATA[<p>Every now and then I stumble upon a tidbit of information that just makes me want to kick myself.  Today was one of those days.  Just by chance I ended up at <a href="http://php.net/manual/en/function.json-encode.php">an entry on PHP.net</a> while Googling another issue.  Once I realized what this function was capable of I was torn between thinking &#8220;Wow, this is awesome!&#8221; and &#8220;Wow, I&#8217;m a dumbass!&#8221;</p>
<pre class="brush: php; title: ; notranslate">
$array = array (
    'alpha'=&gt;4,
    'beta'=&gt;9,
    'gamma'=&gt;3
);
echo json_encode($array)
</pre>
<p>You should then see something like the following:</p>
<pre class="brush: plain; title: ; notranslate">{&quot;alpha&quot;:4,&quot;beta&quot;:9,&quot;gamma&quot;:3}</pre>
<p>If you were manually processing the array and building a JSON object like I was, assume the face palm position.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fettesps.com/php-converting-an-array-to-json/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dynamic Variable Names in PHP</title>
		<link>http://www.fettesps.com/dynamic-variable-names-in-php/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dynamic-variable-names-in-php</link>
		<comments>http://www.fettesps.com/dynamic-variable-names-in-php/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 12:13:45 +0000</pubDate>
		<dc:creator>FettesPS</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[eval]]></category>

		<guid isPermaLink="false">http://www.fettesps.com/?p=958</guid>
		<description><![CDATA[Anyone who has spent a large amount of time programming in PHP has probably used it&#8217;s dynamic variable name feature at least once. For those of you who are unfamiliar with it&#8217;s usages I will give a quick example: The above is a method I often use to make sure that all POST or GET [...]]]></description>
			<content:encoded><![CDATA[<p>Anyone who has spent a large amount of time programming in PHP has probably used it&#8217;s dynamic variable name feature at least once. For those of you who are unfamiliar with it&#8217;s usages I will give a quick example:</p>
<pre class="brush: php; title: ; notranslate">
foreach($_POST as $i=&gt;$p) {
  ${$i} = myreal_escape_string($p);
}
</pre>
<p>The above is a method I often use to make sure that all POST or GET variables are sanitized.  Since I typically use a templating engine I can simply call this before loading my template files and their code.  You may be wondering what else you could use this for, or why you&#8217;d ever need it, the truth is you probably hardly ever will.  Beyond the example I just gave the only other time I&#8217;ve seen it in use was when I downloaded some open source code that had a few added features which required you to purchase them.  Since the code was all there for me to read I was curious as to what the author did to stop users from just enabling the features themselves.  What I discovered was the author had used several dynamic variable names to hide them in the code.  In each reference of the variable a different algorithm was used to generate the same variable name, so if you tried to search the code for it you would never find a match.  Eventually I did figure it out and was able to enable the features, but out of respect for the author I never did use them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fettesps.com/dynamic-variable-names-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Auto Convert URLs to Links in a Block of Text</title>
		<link>http://www.fettesps.com/php-auto-convert-urls-to-links-in-a-block-of-text/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-auto-convert-urls-to-links-in-a-block-of-text</link>
		<comments>http://www.fettesps.com/php-auto-convert-urls-to-links-in-a-block-of-text/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 22:13:43 +0000</pubDate>
		<dc:creator>FettesPS</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[preg_match]]></category>
		<category><![CDATA[preg_replace]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[regular expression]]></category>

		<guid isPermaLink="false">http://www.fettesps.com/?p=269</guid>
		<description><![CDATA[Whether you&#8217;re creating your own custom blog, tweaking a CMS or building a plugin this is one block of code that can come in very handy. I&#8217;ve used this many times over the years and it has always served me well. I will admit, I am terrible with regular expressions and found this a while [...]]]></description>
			<content:encoded><![CDATA[<p>Whether you&#8217;re creating your own custom blog, tweaking a CMS or building a plugin this is one block of code that can come in very handy.  I&#8217;ve used this many times over the years and it has always served me well.  I will admit, I am terrible with regular expressions and found this a while back, so I can take no credit for it. Usually I use something like <a href="http://txt2re.com/" target="_new">txt2re</a> when I a cutomer regular expression.</p>
<pre class="brush: php; title: ; notranslate">$pattern = &quot;@\b(https?://)?(([0-9a-zA-Z_!~*'().&amp;=+$%-]+:)?[0-9a-zA-Z_!~*'().&amp;=+$%-]+\@)?(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\@&amp;=+$,%#-]+)*/?)@&quot;;

$text = preg_replace($pattern, '&lt;a href=&quot;\0&quot;&gt;\0&lt;/a&gt;', $text_raw);</pre>
<p>Hopefully someone else finds it useful <img src='http://www.fettesps.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.fettesps.com/php-auto-convert-urls-to-links-in-a-block-of-text/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Automatically Submit Your WordPress Posts to Twitter</title>
		<link>http://www.fettesps.com/automatically-submit-your-wordpress-posts-to-twitter/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=automatically-submit-your-wordpress-posts-to-twitter</link>
		<comments>http://www.fettesps.com/automatically-submit-your-wordpress-posts-to-twitter/#comments</comments>
		<pubDate>Fri, 29 May 2009 21:16:24 +0000</pubDate>
		<dc:creator>FettesPS</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[tweet]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.fettesps.com/?p=134</guid>
		<description><![CDATA[Find yourself constantly twittering about your new blog post to increase your SEO for you blog. Save yourself some time by downloading and installing WordTwit on your blog. All you have to do is configure your username and password and activate the plugin. Update: Well it seems it wasn&#8217;t quite as simple as I first [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Find yourself constantly twittering about your new blog post to increase your SEO for you blog.  Save yourself some time by downloading and installing <a href="http://www.bravenewcode.com/wordtwit/">WordTwit</a> on your blog.  All you have to do is configure your username and password and activate the plugin.</p>
</div>
<div style="font-weight:bold">Update:</div>
<div>Well it seems it wasn&#8217;t quite as simple as I first thought.  By default WordTwit wants to shrink your URLs by using either TinyURL or it&#8217;s own build in algorithm, which doesnt work.  Since TinyURL doesn&#8217;t help me in terms of SEO I wanted to disable this feature completely.  So in order to do that I first had to load up the options to WordTwit by going to Settings-&gt;WordTwit.  Then scroll down to URL Shortenning and make sure Local is selected from the method drop down box.  Now hit Update Options and then go to Plugins, hit the edit button next to WordTwit and look for the function call &#8220;wordtwit_make_tinyurl.&#8221;  We&#8217;re going to tell it to just return the original URL for the local option.  You&#8217;re function should now look like this:</div>
<pre class="brush: php; title: ; notranslate">function wordtwit_make_tinyurl( $link, $update = true ) {
if ( strpos( $link, 'http://' ) === false) {
return $link;
}
$settings = wordtwit_get_settings();
if ( $settings['url_type'] == 'tinyurl' ) {
return twit_get_tiny_url( $link );
} else if ( $settings['url_type'] == 'local' ) {
return $link;
#return wordtwit_tinyurl( $link, $update );
}
}
</pre>
<p>Now hit update file and try it out again.  This time it should post the actual URL to your blog entry.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fettesps.com/automatically-submit-your-wordpress-posts-to-twitter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Writing An A to Z Loop</title>
		<link>http://www.fettesps.com/php-writing-an-a-to-z-loop/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-writing-an-a-to-z-loop</link>
		<comments>http://www.fettesps.com/php-writing-an-a-to-z-loop/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 05:03:48 +0000</pubDate>
		<dc:creator>FettesPS</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[chr]]></category>
		<category><![CDATA[loop]]></category>

		<guid isPermaLink="false">http://www.fettesps.com/blog/?p=15</guid>
		<description><![CDATA[I was recently developing a PHP scraping script to extract the contents of a couple of websites and I wanted to find a quick way to run through a loop for each letter of the alphabet.  I figured since PHP was so versatile there had to be a quick and easy way, so I did [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently developing a PHP scraping script to extract the contents of a couple of websites and I wanted to find a quick way to run through a loop for each letter of the alphabet.  I figured since PHP was so versatile there had to be a quick and easy way, so I did a bit of thinking and came up with this:</p>
<pre class="brush: php; title: ; notranslate">for($alpha = 65; $alpha &amp;lt;= 90; $alpha++) {
      echo chr($alpha);
}</pre>
<p>Simple!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fettesps.com/php-writing-an-a-to-z-loop/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

