<?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>Geek Gumbo &#187; PHP</title>
	<atom:link href="http://www.geekgumbo.com/category/webdev/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.geekgumbo.com</link>
	<description>A potpourri of Web Development, Linux, and Windows tips, tidbits, and observations</description>
	<lastBuildDate>Thu, 02 Feb 2012 20:31:28 +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>The PHP Switch Statement</title>
		<link>http://www.geekgumbo.com/2012/02/02/the-php-switch-statement/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-php-switch-statement</link>
		<comments>http://www.geekgumbo.com/2012/02/02/the-php-switch-statement/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 20:31:28 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=4271</guid>
		<description><![CDATA[The PHP switch statement is a good substitute for a lot of "if, "else", and "elseif" statements. The switch statement is much more efficient than the "if", "elseif" statements, however there are some quirks that you should be aware of &#8230; <a class="more-link" href="http://www.geekgumbo.com/2012/02/02/the-php-switch-statement/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The PHP switch statement is a good substitute for a lot of "if, "else", and "elseif" statements.  The switch statement is much more efficient than the "if", "elseif" statements, however there are some quirks that you should be aware of in using switch.   This article came when I wanted to do an "or" condition in one of the case tags.  As usual, it took me awhile to find what I wanted.  I thought it would help if I put all the quirks in one article.  </p>
<p>First, lets look at the basic switch statement. </p>
<pre class="brush:php">
include "chk.php";
$var = 0;
new chk($var);
SwitchDemo($var);
function SwitchDemo($var)
{
  switch ($var)
  {
    case 0:
		echo "Hello";
		break;
    case 1:
	        echo " World!";
		break;
    case 2:
	        echo "The real McCoy";
	        break;
    case 3:
                echo "Went too far";
	        break;
    case 4 :
		if ($type == "string" ) {
                    $myarray = array_push($buildarr, $type);
                    break;
                }
		break;
    default:
	    echo "went way too far";
	    break;
	}
}
</pre>
<p>Here's the code we'll use initially to test things out.  A word of explanation.  Include "chk.php" is my free variable checking class that you can <a href="http://www.newchk.com/" title="NewChk.com">read about and download here</a>.  To use the class, I simply say "new chk($var);".  The output is in the picture below.  The output says $var is an integer set to "0" that was called in my test script file, "switch.php", on line 21.  The output of the switch statement is "Hello".</p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2012/01/switch152.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2012/01/switch152.png" alt="" title="switch15" width="600" height="99" class="aligncenter size-full wp-image-4279" /></a></p>
<p>This is a standard switch statement that we'll start with so you can quickly refer to the syntax when needed.  The switch statement executes a different section of code depending on which case is true.   The switch variable to be checked should be in parenthesis, and each case tag ends with a ":", a colon, although if you messed up and used a semicolon, I think you'll find that it still works.  I'll let you test that out on your own.  Note the brackets surrounding all the case and default tags.  Also, notice in Case 4, you can have a fairly complex series of commands in the case block, not just one or two lines.  We'll leave Case 4 out in the rest of this article just to keep things simple.  </p>
<p>The first thing to know is the switch statement does a "loose" comparison between the value in the switch parenthesis and the case value, as opposed to a strict comparison.  This would be like using a == in an if statement, instead of a ===.  Let's just say that switch does a pretty good job, and if there's any doubt, re-do the variable to make sure there's no ambiguity, that can mean, just making the comparison all integers.  If your using integers to compare, you do not need quotes around the integers as shown in our first example.  With strings, put quotes around the string.</p>
<p>OK, lets move on.  The default case is used, if none of the other case statements are true.  A little known fact is the case statements, and the default statement, don't need to be in any sort of order.  Let's move the default up, change the case statements around, and change our variable to 2 to better show this.  Here's the code scrambled.  I'll cut down the code to show just the switch statement.  The other code is still running.</p>
<pre class="brush:php">
	switch ($var)
	{
	    case 3:
              echo "Went too far";
	      break;
	    default:
	      echo "went way too far";
	      break;
            case 1:
	      echo "World!";
              break;
	case 0:
   	      echo "Hello";
	      break;
    case 2:
	    echo "The real McCoy";
	    break;
</pre>
<p>And here's the output:</p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2012/01/switch25.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2012/01/switch25.png" alt="" title="switch25" width="600" height="106" class="aligncenter size-full wp-image-4284" /></a></p>
<p>Next, we want to talk about "break" and "continue".  "break;" breaks you out of the switch statement all together.  You're done your filtering, and you're moving on. "continue;" means move to the next case block.  Let's show this, we'll put the switch back in order and use a continue.</p>
<pre class="brush:php">

switch ($var)
{
    case 0:
		echo "Hello";
		continue;
    case 1:
	    echo "World!";
		break;
    case 2:
	    echo "The real McCoy";
	    break;
    case 3:
        echo "Went too far";
	    break;
    default:
	    echo "went way too far";
	    break;
}
</pre>
<p>Here's the output:</p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2012/01/switch35.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2012/01/switch35.png" alt="" title="switch35" width="600" height="106" class="aligncenter size-full wp-image-4287" /></a></p>
<p>I know you were expecting "Hello World", lol.  No, even though we are "continuing" to match case blocks, we still have to match.  Which brings me to why I wrote the article: How can I output "Hello World!" ?</p>
<p>We'll use a not well known feature of the switch, the "fall through" in the switch statement.  If we take out the continue, and leave the break on case 1, we'll get close to our desired results.  Here's the code:</p>
<pre class="brush:php">
switch ($var)
{
    case 0:
	    echo "Hello";
    case 1:
	    echo " World!";
		break;
    case 2:
	    echo "The real McCoy";
	    break;
    case 3:
            echo "Went too far";
	    break;
    default:
	    echo "went way too far";
	    break;
}
</pre>
<p>Here's the output:</p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2012/01/switch55.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2012/01/switch55.png" alt="" title="switch55" width="600" height="109" class="aligncenter size-full wp-image-4289" /></a></p>
<p>In this case, there was no break for Case 0, so when the $var was 0, it outputs "Hello World!"  It fell through to Case 1.  What happens if we set the $var to 1.  Here's the output.</p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2012/01/switch65.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2012/01/switch65.png" alt="" title="switch65" width="600" height="107" class="aligncenter size-full wp-image-4290" /></a></p>
<p>Here we did not match the "0", so "Hello" did not output, and because the HTML tags were not correct the CSS styling did not load, and make "World!" bigger.  Let's fix this and make the switch statement really useful.  Here's the code:</p>
<pre class="brush:php">
switch ($var)
{
    case 7:
    case 8:
    case 0:
    case 1:
	    echo "Hello World!";
		break;
    case 2:
	    echo "The real McCoy";
	    break;
    case 3:
        echo "Went too far";
	    break;
    default:
	    echo "went way too far";
	    break;
	}
</pre>
<p>Here's the output:</p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2012/01/switch85.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2012/01/switch85.png" alt="" title="switch85" width="600" height="101" class="aligncenter size-full wp-image-4292" /></a></p>
<p>Woo horsey!   What's going on here?  We put in a variable of 8 and we get "Hello World!" What happen is the case block matched the 8 and fell through to case 1 and out came "Hello World!". We then broke out of the switch statement.  What this means to you is that you can use "OR" conditions with the switch statement.  </p>
<p>Instead of:<br />
<code></p>
<pre class="brush:php">

if( $var == 7 || $var == 8 || $var == 0 || $var == 1) {

}
</pre>
<p></code></p>
<p>We can use our switch statement above, which seems a lot easier to me, and more important less prone to syntax errors when we have "OR" statements.</p>
<p>One last thing, we can use calculations in our matches.  Let do a final example.  Here we'll go back to all the code, and use more than one variable.  Here's the code:</p>
<pre class="brush:php">

include "chk.php";
$var1 = 1;
$var4 = 4;
new chk($var1, $var4);

SwitchDemo($var1, $var4);
function SwitchDemo($var1, $var4)
{
switch ($var1 + $var4)
{
    case 7:
    case 8:
    case 0:
    case 1:
	    echo "Hello World!";
	    break;
    case (2 + 3):
	    echo "The real McCoy";
	    break;
    case 3:
            echo "Went too far";
	    break;
    default:
	    echo "went way too far";
	    break;
	}
}
</pre>
<p>Here's the output:</p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2012/01/switch115.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2012/01/switch115.png" alt="" title="switch115" width="600" height="132" class="aligncenter size-full wp-image-4294" /></a></p>
<p>Here we used calculations, a simple add, in both the switch parameter statement and the case parameter, and we get "The real McCoy." This is equivalent to:</p>
<pre class="brush:php">
if( $var1 && $var2)  {

}
</pre>
<p>We've used switch to add variables, and check for an "AND" condition.  You can use this to concatenate strings, if you like.  You can see the versatility of the switch statement.</p>
<p>In conclusion, the switch statement is more efficient than the "elseif" type of statement.  The interpreter makes a list of case comparisons, and then goes right to the case that matches instead of checking every comparison one at a time.  Hopefully, you won't shy away from using the switch statement in the future now that you know all the ins and outs. Chow, until next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2012/02/02/the-php-switch-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP array_push, and other array manipulators</title>
		<link>http://www.geekgumbo.com/2012/01/12/php-array_push-array_pop-array_shift-array_unshift/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-array_push-array_pop-array_shift-array_unshift</link>
		<comments>http://www.geekgumbo.com/2012/01/12/php-array_push-array_pop-array_shift-array_unshift/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 20:35:45 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[Sorting Arrays]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=4140</guid>
		<description><![CDATA[Every once and a while I like to take a closer look at a particular function that I use quite frequently. This let's me make sure I'm using that particular function to the best possible effect. I find it also &#8230; <a class="more-link" href="http://www.geekgumbo.com/2012/01/12/php-array_push-array_pop-array_shift-array_unshift/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.geekgumbo.com/wp-content/uploads/2012/01/antarray15.jpg"><img src="http://www.geekgumbo.com/wp-content/uploads/2012/01/antarray15.jpg" alt="" title="antarray15" width="150" height="113" class="alignleft size-full wp-image-4193" /></a>Every once and a while I like to take a closer look at a particular function that I use quite frequently.  This let's me make sure I'm using that particular function to the best possible effect.  I find it also shifts the center of attention from a task to how the function operates.  A different look so to speak.  Today, I want to cover the PHP array manipulator family functions that include: <span style="color:red;">array_push</span>, <span style="color:red;"> array_pop</span>, <span style="color:red;">array_shift</span> and <span style="color:red;">array_unshift</span>.  </p>
<p>All the examples below are visualized with my free, open-source, variable checker that you are welcome to download from my newchk site at <a href="http://www.newchk.com/" title="newchk">www.newchk.com</a>  Documentation on how to use it is on the site.  </p>
<p><span style="color:blue;"><strong>ARRAY_PUSH</strong></span></p>
<p>Array_push($new_array, $var1, $var2, ...) pushes one or more array elements on to the end of an array, in this case, we'll use $new_array as our array.  Seems simple enough.  I want to create a new array, and add some variables to it. Let's take a look.</p>
<p>Let's set up our new array.<br />
<code></p>
<pre class="brush:php">
$new_array = array();
$var1 = "buick";
$var2 = "ford";
$var3 = "toyota";
array_push($new_array, $var1, $var2, $var3);
</pre>
<p></code><br />
Let's take a look at $new_array;</p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2012/01/array151.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2012/01/array151.png" alt="" title="array15" width="600" height="75" class="aligncenter size-full wp-image-4167" /></a></p>
<p>If $new_array already exists with elements in it, then new variables are appended to the end of the already existing array.  Let's show that.<br />
<code></p>
<pre class="brush:php">
$var_food1 = "cheese";
$var_food2 = "meat";
$var_food3 = "potatoes";
array_push($new_array, $var_food1, $var_food2, $var_food3);
</pre>
<p></code><br />
Here's what the $new_array looks like now.  </p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2012/01/array251.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2012/01/array251.png" alt="" title="array25" width="600" height="128" class="aligncenter size-full wp-image-4171" /></a></p>
<p>Some things to note about the array_push() function.  It is a function, so there is no equal sign used with array_push.  The order the variables are pushed on to the end of the array are in the order their listed in array_push.  We can also use associative keys with array_push(), like so.</p>
<p><code></p>
<pre class="brush:php">
$var_ball1 = "football";
$var_ball2 = "the rock";
$var_ball3 = "hardball";
$ball_array = array("ball_football" => $var_ball1, "ball_basketball" =>$var_ball2, "ball_baseball" =>$var_ball3);
array_push($new_array, $ball_array );
</pre>
<p></code><br />
Here's what the $new_array looks like now.  </p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2012/01/array_push351.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2012/01/array_push351.png" alt="" title="array_push35" width="600" height="196" class="aligncenter size-full wp-image-4173" /></a></p>
<p>We've done a little more here than just assign associative keys to the array.  We've jumped to what is called a multi-dimensional array.  We now have an array within an array.  If you look at the code above you see when working with multi-dimensional arrays, you build the inner array first, in this case the $ball_array, and then do an array_push using $ball_array as the variable in the array_push.</p>
<p>What got me to write this article was I was trying to do an array_push in a foreach loop using a multi-dimensional array.  This is not well documented on the Internet.  I had to look for awhile to find the proper syntax.  When that happens I tend to write an article about it.  The trick is to make a separate array variable before doing the array_push, and then add that array as a variable to the array_push().</p>
<p>Where do you most often use the array_push() function?  Most of the time it's with a foreach loop, where your repetitively looping through an array, and creating a new subset of the array with array_push.  Let's see.<br />
<code></p>
<pre class="brush:php">
$for_array = array();
$i = 1;
foreach( $new_array as $row)
{
	if($i < 7 )
	{
		array_push($for_array, $row );
	}
	$i ++;
}
</pre>
<p></code></p>
<p>Here, with a foreach loop, we've removed the second array, and are back to a one dimensional array, called $for_array.</p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2012/01/array_push451.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2012/01/array_push451.png" alt="" title="array_push45" width="600" height="125" class="aligncenter size-full wp-image-4175" /></a></p>
<p><span style="color:blue;"><strong>ARRAY_POP</strong></span></p>
<p>Array_pop($array) pops an element off the end of an array.  Let's do it </p>
<p><code></p>
<pre class="brush:php">

$spuds = "";
$spuds = array_pop($for_array);
</pre>
<p></code><br />
Our $for_array now is minus the last element in the previous array. That element is now in a separate $variable called $spuds.  Array_pop() removes the last element in the array, which you can then put into a separate variable.</p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2012/01/array551.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2012/01/array551.png" alt="" title="array55" width="600" height="150" class="aligncenter size-full wp-image-4177" /></a></p>
<p><span style="color:blue;"><strong>ARRAY_SHIFT</strong></span></p>
<p>What if we wanted to remove the first element in the array, instead of the last, like we do with array_pop().  We'll we use array_shift to do this, like so.<br />
<code></p>
<pre class="brush:php">

$gm = "";
$gm = array_shift($for_array);
</pre>
<p></code><br />
The $for_array we started with is getting shorter as the first variable in the array is removed, and put, in this case, in the variable $gm.</p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2012/01/array651.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2012/01/array651.png" alt="" title="array65" width="600" height="132" class="aligncenter size-full wp-image-4179" /></a></p>
<p><span style="color:blue;"><strong>ARRAY_UNSHIFT</strong></span></p>
<p>Finally, since array_push added new variables to the end of the array, you probably have guessed that there is a function that adds variable to the front of the array, and you'd be right. I present to you, array_unshift().  Array_unshift() puts the new variable as the first element in your array.  Let's do it.<br />
<code></p>
<pre class="brush:php">

$gm2 = "cadillac";
array_unshift($for_array, $gm2);
</pre>
<p></code><br />
Our array now looks like this.</p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2012/01/array751.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2012/01/array751.png" alt="" title="array75" width="600" height="113" class="aligncenter size-full wp-image-4180" /></a></p>
<p>We've replaced the "buick" we've taken off the top of the array with array_shift, and upgraded to a "cadillac" with array_unshift.  Nice trade-up.</p>
<p>If your working with multi-dimensional arrays, the key is to treat the nested arrays as a single array variable, and then use the four functions we've covered: array_push, array_pop, array_shift and array_unshift with that single array variable.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2012/01/12/php-array_push-array_pop-array_shift-array_unshift/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Tools</title>
		<link>http://www.geekgumbo.com/2011/12/31/php-tools/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-tools</link>
		<comments>http://www.geekgumbo.com/2011/12/31/php-tools/#comments</comments>
		<pubDate>Sat, 31 Dec 2011 15:15:37 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=4097</guid>
		<description><![CDATA[Happy New Year!  For the start of the new year, I thought I'd review some of the PHP tools you should be learning, and using, to up your game in the coming year. One of the challenges of a technical &#8230; <a class="more-link" href="http://www.geekgumbo.com/2011/12/31/php-tools/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.geekgumbo.com/wp-content/uploads/2011/12/images.jpeg"><img class="alignleft size-full wp-image-4106" title="images" src="http://www.geekgumbo.com/wp-content/uploads/2011/12/images.jpeg" alt="" width="267" height="189" /></a>Happy New Year!  For the start of the new year, I thought I'd review some of the PHP tools you should be learning, and using, to up your game in the coming year.</p>
<p>One of the challenges of a technical career is that your always wondering if you learn a new technology, if its going to be a waste of time.  You're constantly learning new things, and every time you're presented with the challenge of implementing something you've never done before you have to wonder if this technology will be around in another three years.  Technology moves that fast.</p>
<p>As you gain more experience in your chosen expertise, you get more selective in the tools your willing to spend time to learn.  Along those lines I thought it might be nice to do a light over view of where I see PHP tools at this moment in time.  These are the tools that I hear currently mentioned the most on the web, in workshops, and conferences.  In other words, the current tools of choice, and the tools you should seriously consider working with and learning.</p>
<p>First of all, we all should be using object-oriented coding.  <span style="color: #008080;"><a title="PHP 5.3" href="http://php.net/releases/5_3_0.php"><span style="color: #008080;">PHP 5.3</span></a></span> is the way to go for now. The old procedural coding, for the most part, is dead.  I believe colleges are all teaching object-oriented now, so this is not a big deal.</p>
<p>Although, it seems MySQL is still the database of choice, I've seen a lot of use of two other databases you should be considering.  A file based <span style="color: #008080;"><a title="SQLite" href="http://www.sqlite.org/"><span style="color: #008080;">SQLite</span></a></span>.  It works great, and is super quick, except when you start to get into heavy transactions.  It's used to replace configuration and XML files, works great for mobile devices, and for small and medium size web site databases.</p>
<p>You might think that MySQL kicks in about then, but if you want to consider an alternative, I've been seeing the <span style="color: #008080;"><a title="PostgreSQL" href="http://www.postgresql.org/"><span style="color: #008080;">PostgreSQL</span></a></span> database coming on strong.  For one thing, it's not Oracle controlled.  Oracle starts charging after you cross over a certain usage line.  It is the database of choice for raw speed doing complex tasks, like constantly displaying data for constantly updating weather monitors.</p>
<p>For JavaScript, hands down <span style="color: #008080;"><a title="jQuery" href="http://jquery.com/"><span style="color: #008080;">jQuery</span></a></span> has been adopted universally.  Other tools I hear mentioned are <span style="color: #008080;"><a title="Mootools" href="http://mootools.net/"><span style="color: #008080;">Mootools</span></a></span>, and <span style="color: #008080;"><a title="Dojo" href="http://dojotoolkit.org/"><span style="color: #008080;">Dojo</span></a></span>.   For Ajax applications, I again hear jQuery.  jQuery has become so popular that is incorporated into a lot of PHP frameworks.</p>
<p>Speaking of PHP frameworks, there is a lot of buzz surrounding <span style="color: #008080;"><a title="Zend Framework 2" href="http://framework.zend.com/wiki/pages/viewpage.action?pageId=42303506"><span style="color: #008080;">Zend Framework 2</span></a></span>. The developers have reworked this PHP Framework to improve overall performance and take advantage of all the new features in PHP 5.3.  There has been an open forum during the development to get the best ideas from other PHP developers and implement them.  Consideration has been given to improving performance every step of the way.  The framework is currently in Beta release.  The documentation on the web on how to use this new release is starting to swell.  There are a lot of other good frameworks out there, but you should still spend some time to get to know ZF2, as its called, because of the extensive libraries of code available to ease your coding tasks.</p>
<p>Second, PDO and ORM for the database to PHP object type mismatch are important technologies.  You use PDO, for example, if you started with a MySql database and wanted to switch to the PostgreSQL database.  PDO makes switching databases easier.  ORM translates SQL database output to PHP objects for use in your application.  It makes coding database applications faster and easier with less problem in getting SQL queries correct.</p>
<p>There are many ORM options out there, however, the new Zend Framework 2 has settled on using Doctrine 2.  This makes <span style="color: #008080;"><a title="Doctrine 2" href="http://www.doctrine-project.org/"><span style="color: #008080;">Doctrine 2</span></a></span> the de facto standard to learn for applying PDO and ORM to your application, and make no mistake, don't let those SQL bigots get to you.  It is a benefit to code with an ORM.  Take it from me that has done it both ways.</p>
<p>A lot of frameworks now include testing components in the framework.  The testing component that is fast becoming the de facto standard is <span style="color: #008080;"><a title="PHPUnit" href="http://www.phpunit.de/manual/3.6/en/automating-tests.html"><span style="color: #008080;">PHPUnit</span></a></span>.  One new technology you should gradually start applying is unit tests.  The best way to start is to set up the testing environment, and write a couple of tests for your project, then gradually write a couple of more, expanding your test suite. Pretty soon you'll get the hang of it and it will become second nature.</p>
<p>For version control the current hot software is <span style="color: #008080;"><a title="Git" href="http://git-scm.com/"><span style="color: #008080;">Git</span></a></span>.  You should be using version control for all your projects.  Because Git is so popular, <span style="color: #008080;"><a title="Github" href="https://github.com/"><span style="color: #008080;">GitHub</span></a></span> has become a mecca for releasing open source software, install Git, and join GitHub. Git runs on all platforms, if you haven't used version control software it's time to start.</p>
<p>For documenting your code you should be following the <span style="color: #008080;"><a title="phpDocumentor" href="http://www.phpdoc.org/"><span style="color: #008080;">phpDocumentor</span></a></span> syntax.  phpDocumentor has been the standard for a couple of years now.  My time spent learning how to document my code properly was well worth the time I spent looking over the phpDocumentor documentation.</p>
<p>Coding to a standard, so that all your code is written in the same format is good coding.  To help you check your code for syntax errors, and format your code for your custom style automatically, use <span style="color: #008080;"><a title="PHP Code Sniffer" href="http://pear.php.net/package/PHP_CodeSniffer/redirected"><span style="color: #008080;">PHP Code Sniffer</span></a></span>.  This will also check your  CSS, and JavaScript. PHP Code Sniffer is installed through the Pear library.</p>
<p>Incidentally, if you're wondering what good code formatting looks like, I can recommend two references that I've run across.  One is on the web, in the <span style="color: #008080;"><a title="Kohana styling" href="http://kohanaframework.org/3.0/guide/kohana/conventions"><span style="color: #008080;">Kohana</span></a></span> framework documentation, and the other is in a book, "<span style="color: #008080;"><a title="Advanced PHP Programming" href="http://www.amazon.com/Advanced-PHP-Programming-George-Schlossnagle/dp/0672325616/ref=sr_1_1?s=books&amp;ie=UTF8&amp;qid=1325341062&amp;sr=1-1"><span style="color: #008080;">Advanced PHP Programming</span></a></span>" by George Schlossnagle.  The important thing on code formatting is to choose a style and consistently use it in all your coding.</p>
<p>If you'd like a report on your code base, the number of lines of code, the complexity, the percentage of comments, number of classes, possible coding violations, bad practices with a bunch of other metrics.  The tool I hear mentioned is <span style="color: #008080;"><a title="Sonar" href="http://docs.codehaus.org/display/SONAR/Documentation"><span style="color: #008080;">Sonar</span></a></span>.</p>
<p>To build your application, run your test suite, and run every thing else with one command, like a "make" file, the application you want is <span style="color: #008080;"><a title="Phing" href="http://www.phing.info/trac/"><span style="color: #008080;">Phing</span></a></span>.</p>
<p>If you would like to automate several projects and run them on a schedule, "<span style="color: #008080;"><a title="CruiseControl" href="http://cruisecontrol.sourceforge.net/   "><span style="color: #008080;">CruiseControl</span></a></span>," will do that for you.  CruiseControl offers flexible scheduling, notifications, and integrates with Phing with a "<span style="color: #008080;"><a title="PHP Under Control" href="http://phpundercontrol.org/"><span style="color: #008080;">PHP Under Control</span></a></span>" plugin.</p>
<p>To solve your scaling problems for those web sites that start out small and get bigger really fast, and to get off of having to depend on your own hardware solution, or that of a commercial hosting company, there is a lot of good reasons to try out <span style="color: #008080;"><a title="Amazon Web Services" href="http://aws.amazon.com/"><span style="color: #008080;">Amazon Web Services</span></a></span>. There are other services out there, but Amazon stands way above all the others in features and pricing.</p>
<p>Don't get me wrong.  In each one of these categories other companies and developers have spent their time creating tools that do the same thing.  These other tools may be just as good, or even better.  I don't mean to put any of these other tools down.  All I'm suggesting is, at this moment in time, this is a tool you should consider spending your time learning, and that it probably would not waste your time.  If you prefer another tool, go for it, and let me know so I can take a look at it too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2011/12/31/php-tools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework 2.0.0 Beta 1 Released</title>
		<link>http://www.geekgumbo.com/2011/11/16/zend-framework-2-0-0-beta-1-released/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=zend-framework-2-0-0-beta-1-released</link>
		<comments>http://www.geekgumbo.com/2011/11/16/zend-framework-2-0-0-beta-1-released/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 13:34:33 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[PHP Frameworks]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=3935</guid>
		<description><![CDATA[The most anticipated PHP framework in a number of years, the Zend Framework 2.0 is on track for release in early 2012.  This beta release is the first in a series of beta releases that will happen approximately every six &#8230; <a class="more-link" href="http://www.geekgumbo.com/2011/11/16/zend-framework-2-0-0-beta-1-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.geekgumbo.com/wp-content/uploads/2011/11/zf25.png"><img class="alignleft size-full wp-image-3937" title="zf25" src="http://www.geekgumbo.com/wp-content/uploads/2011/11/zf25.png" alt="" width="300" height="157" /></a>The most anticipated PHP framework in a number of years, the Zend Framework 2.0 is on track for release in early 2012.  This beta release is the first in a series of beta releases that will happen approximately every six weeks.  When the code becomes stable the new framework will move to Release Candidate status just prior to release.</p>
<p>The first Zend Framework has been used by independent and corporate developers with larger development teams ever since it was first announced in December 2007.</p>
<p>As time went on more and more open source PHP frameworks became available to compete with the Zend framework, while the Zend framework added more functionality, became larger, and gradually slowed down.  The newer frameworks were less functional, but considerably faster.</p>
<p>PHP gradually moved to object oriented coding and added namespaces in PHP 5.3. New impovements and changes to PHP itself were not able to be easily incorporated into the first Zend framework.</p>
<p>The result was an outdated framework that was slower than the newer frameworks available. It was time for an upgrade.</p>
<p>The goals of Zend Framework 2 were to be considerably faster in the range of the faster PHP frameworks, to make the Zend framework much easier to learn, to be easier to use only what you needed, to be easier to extend for adding new modulues, and to use PHP 5.3 functionality through out the code base.</p>
<p>Much of the code that slowed the framework down has been refactored.  This first Beta release features an updated autoloader with StandardAutoloader, ClassMapAutoloader, and AutoLoad Factory.  A new plugin broker strategy, a refactored routing system, a reworked Exception system to allow catching by exception type, a rewritten session component, refactored View and HTTP components, a new cloud infrastructure component, a scanner component, and a new annotation system.  Finally a Module component for developing modular applications, and a completely reworked MVC layer built on top of an event manager.</p>
<p>They even included a skeleton application and quick start documentation with the Beta to get you started.  That should get your mouth watering, and if it does, you're a true geek.  Forget the wife or  girlfriend, and wrap your head around this puppy.  If you'd like to download the Beta release you can get it from the new <a title="Zend Framework 2 Packages" href="http://packages.zendframework.com/">Zend Framework 2 Packages</a> website, have fun, and help the community get it right.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2011/11/16/zend-framework-2-0-0-beta-1-released/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Modulus Operator</title>
		<link>http://www.geekgumbo.com/2011/08/16/the-modulus-operator/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-modulus-operator</link>
		<comments>http://www.geekgumbo.com/2011/08/16/the-modulus-operator/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 14:21:27 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=3387</guid>
		<description><![CDATA[I was looking through my JavaScript operators the other day and came across the modulus operator.  The modulus operator is used in almost all programming languages, and usually it is represented by a "%" sign.  It performs what is called &#8230; <a class="more-link" href="http://www.geekgumbo.com/2011/08/16/the-modulus-operator/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was looking through my JavaScript operators the other day and came across the modulus operator.  The modulus operator is used in almost all programming languages, and usually it is represented by a "%" sign.  It performs what is called the modulo operation.</p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2011/08/oddeven45.jpg"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/08/oddeven45.jpg" alt="" title="oddeven45" width="600" height="219" class="aligncenter size-full wp-image-3405" /></a></p>
<p>OK, now that I've thrown that at you, how do you use it, what does it do, and of what use is it?</p>
<p>First let's show how its used.  In JavaScript it looks like this:<br />
var result = 14 % 2 ;<br />
The value of "result" is 0 .</p>
<p>And in PHP it looks like this:<br />
$theresult = 15 % 2 ;<br />
The value of "$theresult" is 1 .</p>
<p>a % b is pronounced "a modulo b" where a is the dividend, and b is the divisor.</p>
<p>Not much difference in the two languages syntax, and in fact, it is used with the same syntax in all the web programming languages, such as: ActionScript, C, ColdFusion, Java, JavaScript, Perl, PHP, Python, Ruby, and Tcl.</p>
<p>What does it do?  It gives you the remainder of a division.  In the JavaScript example, 14/2 = 7 with no remainder left over, so the modulo of 14 % 2 = 0.  There is no remainder.  In the PHP example, we have 15/2  = 7 with 1 left over.  So 15 % 2 = 1 since we have a remainder of 1.  Pretty simple.</p>
<p>We can use other numbers than 2 as our divisor.<br />
15 % 4  = 3  The nearest number with no remainder is 12.  15-12 gives us 3.</p>
<p>What happens when you have a minus sign in the divisor?<br />
13 % -4 = 1<br />
The answer always takes the sign of the dividend. So,<br />
-13 % 4 = -1</p>
<p>We can use the modulo with other math operations.<br />
22 % ( 9 + 2) = 0</p>
<p>What if the divisor is bigger then the dividend?  Then the value of the modulo is the same as the dividend.<br />
12 % 16 = 12</p>
<p>What about floats?<br />
0.5 % 0.3 = 0.2</p>
<p>This will work fine with JavaScript, as both integers and floats are the same number data type in JavaScript, but with languages like PHP, that have integers and floats as separate data types, it will not.</p>
<p>PHP has a separate function to do floating modulo, fmod(), like so:</p>
<pre class="brush:php">
$a = 5.7;
$b = 1.3;
$theFloatMod = fmod($a, $b);
or
$theFloatMod = fmod( 5.7, 1.3)
//The answer
$theFloatMod = 0.5;
</pre>
<p>Of course, for integers, PHP uses the same syntax as JavaScript.</p>
<p>Before talking about what the modulo is used for, let's go over the range of possible modulo answers.  If we have $c = $a % $b, then:<br />
1. If $b goes evenly into $a, then we know $c = 0.<br />
2. If $b is bigger than $a, then we know $c = $a.<br />
3. Finally, the way its normally used, where $a is bigger than $b.  The answer will be between $b-1 and 1.</p>
<p>Now, the big question, what's it used for? </p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2011/08/oddandeven25.jpg"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/08/oddandeven25.jpg" alt="" title="oddandeven25" width="400" height="203" class="aligncenter size-full wp-image-3407" /></a>   </p>
<p>Well, we can find the number of 10's, 100's, or 1,000's in a number.  It goes something like this for 10's.</p>
<pre class="brush:php">
$answer = ($theNumber - ($theNumber % 10))/10;

//Let's work an example
$theNumber = 92;
$answer = (92 - (92 % 10))/10 = (92 - 2)/10 = 9

// For 100's the formula would be:
$answer = ($theNumber - ($theNumber % 100))/100;
</pre>
<p>If we are iterating through an array repeatedly to put a grid on the screen, for example, the modulo operator can be used to determine the end of the array, and reset to the beginning index value by using the maximum number of the array, like so: ( (i++) % maxArrayDimension)</p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2011/08/oddeven2.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/08/oddeven2.png" alt="" title="oddeven2" width="400" height="222" class="aligncenter size-full wp-image-3406" /></a></p>
<p>Finally, the main use of the operator is to determine if a number is odd or even, as we did above.  If you divide any number by 2 and it comes up with a modulo of "0", it's an even number.  If it comes up with a "1", it's an odd number.  We then can use this in a conditional statement, and do something with it, for example, a table row, if it's an odd row, we could change the background color of the row for easier reading.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2011/08/16/the-modulus-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Sorting and Renumbering Array Keys</title>
		<link>http://www.geekgumbo.com/2011/07/22/php-sorting-and-renumbering-array-keys/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-sorting-and-renumbering-array-keys</link>
		<comments>http://www.geekgumbo.com/2011/07/22/php-sorting-and-renumbering-array-keys/#comments</comments>
		<pubDate>Fri, 22 Jul 2011 12:27:26 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[Sorting Arrays]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=3276</guid>
		<description><![CDATA[In a previous article I covered sorting arrays when you need to maintain key-value relationships. There are times when your interested in sorting array values, and then have the array keys match the sort. There are three array sorts you &#8230; <a class="more-link" href="http://www.geekgumbo.com/2011/07/22/php-sorting-and-renumbering-array-keys/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In a previous article I covered sorting arrays when you need to maintain key-value relationships.  There are times when your interested in sorting array values, and then have the array keys match the sort.  There are three array sorts you can use for this: sort, rsort, and shuffle.</p>
<p>Let's create a test array, $testarray, we'll work with when looking at the sorts.  I've tried to mix it up with upper case, lower case, and numbers to sort. Here's the array before any sorting is done.</p>
<div id="attachment_3278" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/07/sortnk-none5.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/07/sortnk-none5.png" alt="" title="sortnk-none5" width="600" height="192" class="size-full wp-image-3278" /></a><p class="wp-caption-text">The $testarray unsorted</p></div>
<p></p>
<h2 style="text-align: center;"><span style="text-decoration: underline;"><em><strong>SORT</strong></em></span></h2>
<p>Sort sorts an array from the lowest value to the highest value, and reassigns the keys to match the sort.   </p>
<pre class="brush:php">
sort($testarray);
</pre>
<p>Here what the array looks like after the sort:</p>
<div id="attachment_3279" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/07/sortnk-sort5.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/07/sortnk-sort5.png" alt="" title="sortnk-sort5" width="600" height="190" class="size-full wp-image-3279" /></a><p class="wp-caption-text">sort($testarray)</p></div>
<p>Notice the keys have been relabeled starting at 0, and incrementing by 1 for each field.  You might use this in a drop-down menu with a set array that will never change values.</p>
<p>Sort has some optional second parameters that you can use to change the sort: SORT_REGULAR, which is the same as just using sort(); SORT_NUMERIC, which compares values numerically; SORT_STRING, which compares values as strings; and SORT_LOCAL_STRING, which sorts values as strings depending on your locality.  They are used like so:</p>
<pre class="brush:php">
sort($testarray, SORT_NUMERIC )
</pre>
<p>And here's the result:</p>
<div id="attachment_3280" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/07/sortnk-numeric5.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/07/sortnk-numeric5.png" alt="" title="sortnk-numeric5" width="600" height="193" class="size-full wp-image-3280" /></a><p class="wp-caption-text">sort($testarray, SORT_NUMERIC)</p></div>
<p>You'll notice the numbers are sorted, but not the strings<br />
Let's try the sort with the sort_string parameter:</p>
<pre class="brush:php">
sort($testarray, SORT_STRING)
</pre>
<div id="attachment_3283" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/07/sortnk-string5.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/07/sortnk-string5.png" alt="" title="sortnk-string5" width="600" height="190" class="size-full wp-image-3283" /></a><p class="wp-caption-text">sort($testarray, SORT_STRING)</p></div>
<p>Here the strings are sorted, but the numbers are not.</p>
<p>++++++++++++++++++++++++++++++++++++++</p>
<p></p>
<h2 style="text-align: center;"><span style="text-decoration: underline;"><em><strong>RSORT</strong></em></span></h2>
<p>Rsort is the same as sort only it sorts in the reverse order. You can use the same second parameter you used in sort() with rsort().</p>
<p>Here's the call:</p>
<pre class="brush:php">
rsort($testarray)
</pre>
<p>And here's the results:</p>
<div id="attachment_3290" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/07/sortnk-rsort5.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/07/sortnk-rsort5.png" alt="" title="sortnk-rsort5" width="600" height="196" class="size-full wp-image-3290" /></a><p class="wp-caption-text">rsort($testarray)</p></div>
<p>If you use the second parameter, you can sort just the numbers or strings in reverse order.</p>
<p>Here's the numbers with:</p>
<pre class="brush:php">
rsort($testarray, SORT_NUMERIC)
</pre>
<p>Again, note the strings are not sorted, but the numbers are.</p>
<div id="attachment_3291" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/07/sortnk-rsortnum5.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/07/sortnk-rsortnum5.png" alt="" title="sortnk-rsortnum5" width="600" height="192" class="size-full wp-image-3291" /></a><p class="wp-caption-text">rsort($testarray, SORT_NUMERIC)</p></div>
<p>Here's rsort with the string.</p>
<pre class="brush:php">
rsort($testarray, SORT_STRING)
</pre>
<p>An with the strings reverse sorted, but not the numbers it looks like this:</p>
<div id="attachment_3292" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/07/sortnk-rsortstr5.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/07/sortnk-rsortstr5.png" alt="" title="sortnk-rsortstr5" width="600" height="193" class="size-full wp-image-3292" /></a><p class="wp-caption-text">rsort($testarray, SORT_STRING)</p></div>
<p>++++++++++++++++++++++++++++++++++++++</p>
<p></p>
<h2 style="text-align: center;"><span style="text-decoration: underline;"><em><strong>SHUFFLE</strong></em></span></h2>
<p>Let's move to our final sort, shuffle, that renumbers the keys.  It goes like so:</p>
<pre class="brush:php">
shuffle($testarray)
</pre>
<p>This does exactly what the word says, it shuffles the values in the array and reassigns the keys.  You might want to use this if you have a large array and our testing against varies values that you want to look at randomly.</p>
<p>Here's what the output looks like:</p>
<div id="attachment_3293" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/07/sortnk-shuffle5.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/07/sortnk-shuffle5.png" alt="" title="sortnk-shuffle5" width="600" height="196" class="size-full wp-image-3293" /></a><p class="wp-caption-text">shuffle($testarray)</p></div>
<p>There's not to much more to say about shuffle.</p>
<p>If you like the way the arrays appear in this article, I do this with chk.php.  You can download the utility program for free at <a href="http://www.newchk.com/" title="New Chk Utility">www.newchk.com</a>.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2011/07/22/php-sorting-and-renumbering-array-keys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kohana 3 ORM &#8211; Query Building and Key Word Search</title>
		<link>http://www.geekgumbo.com/2011/07/15/kohana-3-orm-query-building-and-key-word-search/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=kohana-3-orm-query-building-and-key-word-search</link>
		<comments>http://www.geekgumbo.com/2011/07/15/kohana-3-orm-query-building-and-key-word-search/#comments</comments>
		<pubDate>Fri, 15 Jul 2011 21:09:20 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[Kohana 3]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=3257</guid>
		<description><![CDATA[I've been working on a project over the last couple of months using the Kohana 3 framework. I've been knee deep in code. When I'm in this mode, and I run into a problem that takes me a couple of &#8230; <a class="more-link" href="http://www.geekgumbo.com/2011/07/15/kohana-3-orm-query-building-and-key-word-search/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I've been working on a project over the last couple of months using the Kohana 3 framework.  I've been knee deep in code.  When I'm in this mode, and I run into a problem that takes me a couple of hours, I figure it's worth a write up to save someone else some time. </p>
<p>I notice with the Kohana 3.1.3.1 release the codegen module is now included in the release, so you don't have to download it from github.  To use these examples you should turn on the ORM, database, and codegen module in the bootstrap.php file. </p>
<p>Your ORM code will be generated into a /temp directory when you go to url: http://localhost/yoursite/codegen, a file will be created for each database table.  Move the database table files generated to your application/model directory, and we're ready to go. </p>
<p>Here's the scene, we have a populated MySQL database.  In this database, we have a table called reports with various columns including: a rpt_id, user_id, a create_date, save_date, pub_date, and of course, the report, rpt. </p>
<p>We also have a users table with a user_id , dept_id, div_id. and username.  </p>
<p>We're building a search engine for reports.  The user puts a query in the input form.  The form data goes to the controller, where the query is run for output to the results view. </p>
<p>The user puts his report id in the form, and we pull that particular report from the database.  Let write the basic ORM query.  </p>
<pre class="brush:php">

$rptid = $_POST['rptid'];

$queryobj = ORM::factory ('report')
    ->with ('user')
    ->where('reports.rpt_id', '=', $rptid )
    ->find_all();
</pre>
<p>The "->with('user')" joins the two tables. Please see my article on <a href="http://www.geekgumbo.com/2011/05/24/kohana-3-orm-a-working-example/" title="Table Joins">table joins</a>, you need to add the relationship to both model files. The "->find_all()" returns all reports that match the conditional where clause.  Notice, the operator between the elements of the query is "->" and there is only one semicolon at the end.</p>
<p>What comes back in $queryobj is an object of the database record. You then assign "reports->rpt" into your data output array for outputting to the next view. </p>
<p>Let's start building queries. We'll make a change, and bring back more results.</p>
<pre class="brush:php">

$queryobj = ORM::factory('report')
->with('user')
->where ('div_id','=', $groupid )->
->find_all(); 
</pre>
<p>The query builder for "where" in Kohana takes three arguments.  The table column, a logical operator, and the query variable from the user's input form. They are separated with a comma and have single quotes around two of the fields and sometimes the third depending on your variable.  The "div_id" is in your user table, which is picked up automatically, with the user table join.</p>
<p>Normally, you have more than one criteria.  Lets add another where clause. </p>
<pre class="brush:php">

$queryobj = ORM::factory('report')
->with('user')
->where_open()
->where ('div_id','=', $groupid )
->and_where ('reports.pub_date','>',$lastweek )->
->where_close()
->order_by(	'pub_date', 'DESC' )
->find_all(); 
</pre>
<p>You can build a series of where clauses between "where_open" and "where_close".  Each where clause after the first, is added with an "and_where" or "or_where".  If there is an ambiguity with the column name, you can put the table name in front, like "reports.pub_date".  $lastweek is a calculated variable of a MySQL date seven days ago.</p>
<p>++++++++++</p>
<p>Let's go to what took me a couple of hours, the key word search.  We want to search through all the reports for any occurrence of a key word, $keywd, which is returned from the form.  </p>
<p>First, to do a full-text, key word search, your database table must be saved in the MyISAM format.  The normal table format in the MySQL versions above 5.5 is InnoDB. It is possible to convert the database table to MyISAM without losing your data.<br />
There are responses to this in the MySQL forum.</p>
<p>The Key Word Search ++++++++</p>
<p>There is a query in MySQL that goes "WHERE MATCH (reports.rpt) AGAINST ($keywd)" which will go through your reports looking for the $keywd and output only those reports where the $keywd is present.  </p>
<p>Initially, I tried to use this in a query by using the "DB::expr()" method in Kohana.  An DB expression is the only way to use SQL functions within query builders.</p>
<p>Here's an example from the Kohana documentation:</p>
<pre class="brush:php">

$expression = DB::expr('COUNT(users.id)');
</pre>
<p>A DB::expr using "MATCH ( ) AGAINST ( )" didn't work with the Kohana ORM.  </p>
<p>Thanks to the Kohana IRC channel, and Jeremy Bush, aka Zomber, who is a Kohana developer that has worked at building the ORM among his many other Kohana projects, I found out that the Kohana ORM is based on <a href="http://owen.sj.ca.us/~rk/howto/sql92.html" title="SQL92">SQL92</a>, and "MATCH AGAINST" is not supported by the Kohana ORM.  I did notice that "LIKE" was supported by SQL92.</p>
<p>As a result, I was able to craft a query that will match a key word or key words with any column in your table, like so:</p>
<pre class="brush:php">

$queryobj = ORM::factory ( 'report' )
->with ('user')
->where_open()
->and_where( 'reports.rpt', 'LIKE', "%$keywd%" )
->where_close()
->find_all();	
</pre>
<p>"LIKE" will do simple pattern matching.  The key to making this work was putting the % signs around the search word or phrase. The % signs allow you to do "wildcard" searching, which is supported in many databases.  The % at the end matches anything that starts with the $keywd and the reverse for the one at the front of the $keywd.  Without the % sign, the query will not work properly, and yes, you need both sides.  </p>
<p>As you can see, this took a while to figure out.  The clues provided by the Kohana IRC channel #kohana at <a href="http://freenode.net/" title="Freenode">freenode</a>, and, especially Zomber, were invaluable is setting me on the right path, if your stuck in the future, the IRC channel is a good source.  They certainly can help point you in the right direction.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2011/07/15/kohana-3-orm-query-building-and-key-word-search/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Sorting while Maintaining Key and Value Relations</title>
		<link>http://www.geekgumbo.com/2011/07/03/php-sorting-while-maintaining-key-and-value-relations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-sorting-while-maintaining-key-and-value-relations</link>
		<comments>http://www.geekgumbo.com/2011/07/03/php-sorting-while-maintaining-key-and-value-relations/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 02:32:27 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[Sorting Arrays]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=3208</guid>
		<description><![CDATA[PHP has many built in array sorting functions. They are simple to use and provide a multitude of sorting options. I'll cover the sorting in three articles.  These first sort functions all maintain the association between the key fields and &#8230; <a class="more-link" href="http://www.geekgumbo.com/2011/07/03/php-sorting-while-maintaining-key-and-value-relations/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>PHP has many built in array sorting functions. They are simple to use and provide a multitude of sorting options.</p>
<p>I'll cover the sorting in three articles.  These first sort functions all maintain the association between the key fields and array values while sorting. The next sorting article will cover sorting when the key field and value relationship doesn't matter, and the last article will cover custom sorting functions.</p>
<p>To demonstrate sorting, I've created an array, $testArray, that we will use with the various sorting functions. Here's what the array looks like as initialized before sorting.</p>
<div id="attachment_3209" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/07/sort-initial2.png"><img class="size-full wp-image-3209" title="sort-initial2" src="http://www.geekgumbo.com/wp-content/uploads/2011/07/sort-initial2.png" alt="" width="600" height="195" /></a><p class="wp-caption-text">Initial Array Before Sorting</p></div>
<p></p>
<h2 style="text-align: center;"><span style="text-decoration: underline;"><em><strong>Asort</strong></em></span></h2>
<p>To sort an array in PHP most of the commands are easy to use.  The first sort we'll look at is asort().  To use it type,</p>
<pre class="brush:php">

asort($testArray);
</pre>
<p>This is the format for most of your sorting commands.  There is no need to assign the array to another variable.  The next time you use the $testArray it will be sorted like this:</p>
<div id="attachment_3210" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/07/sort-asort2.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/07/sort-asort2.png" alt="" title="sort-asort2" width="600" height="193" class="size-full wp-image-3210" /></a><p class="wp-caption-text">asort($testsarray)</p></div>
<p>Asort() sorts an array so that the array values maintain their associations with their key fields. The sort uses the array values to sort from A-Z, then a-z, then 1 on up.</p>
<h2 style="text-align: center;"><span style="text-decoration: underline;"><em><strong>Arsort</strong></em></span></h2>
<p>Arsort sorts on the array values the same as asort(), only in reverse.  Here is the function:</p>
<pre class="brush:php">

arsort($testArray);
</pre>
<p>and here is the result:<br />
<div id="attachment_3226" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/07/sort-arsort32.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/07/sort-arsort32.png" alt="" title="sort-arsort32" width="600" height="192" class="size-full wp-image-3226" /></a><p class="wp-caption-text">arsort($testArray)</p></div><br />
</p>
<h2 style="text-align: center;"><span style="text-decoration: underline;"><em><strong>Ksort</strong></em></span></h2>
<p>Ksort, for key sort, is the same as "asort" except instead of sorting on array values, it sorts on the key fields, and, at the same time, maintains the associations with the array values.</p>
<p>Here's the function:</p>
<pre class="brush:php">

ksort($testArray);
</pre>
<p>and here's the result:</p>
<p><div id="attachment_3212" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/07/sort-ksort2.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/07/sort-ksort2.png" alt="" title="sort-ksort2" width="600" height="193" class="size-full wp-image-3212" /></a><p class="wp-caption-text">ksort($testArray)</p></div><br />
Notice that the values for two, and nine are not sorted as in asort, but they are in the key field column.</p>
<p></p>
<h2 style="text-align: center;"><span style="text-decoration: underline;"><em><strong>Krsort</strong></em></span></h2>
<p>Krsort is the same as ksort only in reverse key field order.</p>
<p>Here's the function:</p>
<pre class="brush:php">

krsort($testArray);
</pre>
<p>and here's the result:</p>
<p><div id="attachment_3213" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/07/sort-krsort2.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/07/sort-krsort2.png" alt="" title="sort-krsort2" width="600" height="192" class="size-full wp-image-3213" /></a><p class="wp-caption-text">krsort($testArray)</p></div><br />
</p>
<h2 style="text-align: center;"><span style="text-decoration: underline;"><em><strong>Natsort</strong></em></span></h2>
<p>Natsort, for natural sort, sorts on array values using a natural sort algorithm.  It separates upper and lower case and numbers are ordered like: 1, 2, 10, 12 instead of 1, 10, 12, 2.  Array values and key fields maintain their relationships</p>
<p>Here's the function:</p>
<pre class="brush:php">

natsort($testArray);
</pre>
<p>and here's the result:</p>
<p><div id="attachment_3214" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/07/sort-natosrt2.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/07/sort-natosrt2.png" alt="" title="sort-natosrt2" width="600" height="191" class="size-full wp-image-3214" /></a><p class="wp-caption-text">natsort($testArray)</p></div><br />
</p>
<h2 style="text-align: center;"><span style="text-decoration: underline;"><em><strong>Natcasesort</strong></em></span></h2>
<p>Natcasesort, for natural case sort.  This is the same at natsort, only it is case insensitive.  It sorts on array values using a natural sort algorithm.  It separates upper and lower case and numbers are ordered like: 1, 2, 10, 12 instead of 1, 10, 12, 2.  Array values and key fields maintain their relationships</p>
<p>Here's the function:</p>
<pre class="brush:php">

natcasesort($testArray);
</pre>
<p>and here's the result:</p>
<p><div id="attachment_3215" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/07/sort-natcasesort2.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/07/sort-natcasesort2.png" alt="" title="sort-natcasesort2" width="600" height="192" class="size-full wp-image-3215" /></a><p class="wp-caption-text">natcasesort($testArray)</p></div><br />
<br />
Notice that the upper and lower case are not case sensitive.</p>
<p>If you would like to have your arrays displayed as shown in this article, you can download the program for free at <a href="http://www.newchk.com">www.newchk.com</a>.  There is documentation on the web site to show you how to install and use the program.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2011/07/03/php-sorting-while-maintaining-key-and-value-relations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kohana 3 ORM &#8211; Creating a Form Select List</title>
		<link>http://www.geekgumbo.com/2011/06/26/kohana-3-orm-creating-a-form-select-list/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=kohana-3-orm-creating-a-form-select-list</link>
		<comments>http://www.geekgumbo.com/2011/06/26/kohana-3-orm-creating-a-form-select-list/#comments</comments>
		<pubDate>Sun, 26 Jun 2011 17:35:37 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[Kohana 3]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=3134</guid>
		<description><![CDATA[Working with the Kohana 3 ORM, I went through the documentation, and didn't find anything on getting data back from the database, and creating a drop down select list in a form. This involved using a form, the ORM, and &#8230; <a class="more-link" href="http://www.geekgumbo.com/2011/06/26/kohana-3-orm-creating-a-form-select-list/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Working with the Kohana 3 ORM, I went through the documentation, and didn't find anything on getting data back from the database, and creating a drop down select list in a form. This involved using a form, the ORM, and how to format the select list. I thought the combination might be helpful for readers. </p>
<p>I had to create a drop down list of department names in one of my forms. The department names were stored in a look-up table, depts, in my database.  The look up table had two fields: dept_id, and dept_name. Here's what the table looks like in the database. </p>
<div id="attachment_3138" class="wp-caption aligncenter" style="width: 300px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/06/dropdbtable5.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/06/dropdbtable5.png" alt="" title="dropdbtable5" width="290" height="255" class="size-full wp-image-3138" /></a><p class="wp-caption-text">The database table</p></div>
<p>This is an ORM example.  You need the ORM code set up for this to work.  Set up the ORM code by downloading the codegen code from Github.  Then put the unzipped code in your module directory, open your bootstrap file, and turn on the database, ORM, and codegen modules.  Generate your ORM code into a temp directory, and then move the database table files into your application/model directory. Ok, were ready to go.</p>
<p>A word on the select list, or drop down menu.  Almost every form you present to your users has a select drop down box.  You do this to make the user select a value that is in the database, so there is no chance of a user putting in an incorrect entry.  You use these a lot. </p>
<p>Here's the select list code in HTML:</p>
<pre class="brush:html">
<select name="theDept">
<option value="1">Coach</option>
<option value="2">Coordinator</option>
<option value="3">Running Backs</option>
</select>
</pre>
<p>The name is how you get back the value in your $_POST array, like so $_POST['theDept'].  And what comes back is the value of the option the user selected from the drop down box.  Most values are id's from your database table. What shows in the form's drop down box is on the right in the above HTML example.  </p>
<p>Let's see how to get the same HTML code using Kohana, we put this in our view page.</p>
<pre class="brush:php">
echo Form::open ( 'searhcriteria',
		array ('id'=>'theform'));

 echo Form::select('theDept', array(
  	'1'=>'Coach',
  	'2'=>'Cordinator',
  	'3'=>'Running Backs',
  ));
</pre>
<p>I threw in the form open statement so you could see that. The user when he hits the submit button on the web page will send the $_POST values to the "searhcriteria" controller.  The id, "theform" sets up a div for CSS styling.  As in the HTML example, "theDept" is the $_POST['theDept'] variable and the value is the key field in the array. </p>
<p>This is a working example.  I've dropped the example code into my app to create the images on this page.  Let's see what it will look like with with the drop down box closed and open, and with the database populated in the drop down.</p>
<div id="attachment_3139" class="wp-caption alignleft" style="width: 300px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/06/dropnotopen5.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/06/dropnotopen5.png" alt="" title="dropnotopen5" width="290" height="72" class="size-full wp-image-3139" /></a><p class="wp-caption-text">Drop down not open</p></div>
<div id="attachment_3157" class="wp-caption alignright" style="width: 300px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/06/dropopen51.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/06/dropopen51.png" alt="" title="dropopen5" width="290" height="227" class="size-full wp-image-3157" /></a><p class="wp-caption-text">Drop Down Opened Up</p></div>
<p>The code to bring the data back from the database is done with an ORM call, like this:</p>
<pre class="brush:php">
$depts = ORM::factory('dept')->find_all()->as_array('dept_id','dept_name');

$data ['footballdepts'] = $depts;
</pre>
<p>The "ORM::factory" sets up an instance of an ORM object for the data coming from the database. The data will come from the "dept" table.  The actual table name in my database is "depts" plural, the ORM file name is singular "dept".  We use "dept" when referring to the table in the ORM call.  The "find-all" gets all the data from the database table and brings it back as an array of objects.  </p>
<p>We can't use objects in our drop down without converting them to values, normally done with a foreach loop.  However the Kohana ORM has a nice method called "as_array" that will do this on the fly.  The "as_array" method turns the object created with the "find_all" method into an array with the associative key field being the "dept_id" field, and the "dept_name" field being the name displayed in the drop down.</p>
<p>As a shameless plug, using my open-source variable checker, <a href="http://www.newchk.com/">"newchk", that can be downloaded here</a>.  The below output shows the actual data that came back from the database.  This was done with a call to, "new chk($depts);" on the next line of code after the ORM call.  </p>
<div id="attachment_3141" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/06/dropvariable5.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/06/dropvariable5.png" alt="" title="dropvariable5" width="600" height="159" class="size-full wp-image-3141" /></a><p class="wp-caption-text">Using newchk to check the data coming from the database</p></div>
<p>We have our data back from the database in an array. We assign it to the view data array with the next line, "$data['footballdepts'] = $depts;", and send it to the view page. </p>
<p>The Kohana form select call on the view page is done like so:</p>
<pre class="brush:php">

echo Form::select('theDept',$footballdepts);
</pre>
<p>Here's what it looks like in your form open and closed.</p>
<div id="attachment_3139" class="wp-caption alignleft" style="width: 300px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/06/dropnotopen5.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/06/dropnotopen5.png" alt="" title="dropnotopen5" width="290" height="72" class="size-full wp-image-3139" /></a><p class="wp-caption-text">Dropdown not open</p></div>
<div id="attachment_3140" class="wp-caption alignright" style="width: 300px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/06/dropopen5.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/06/dropopen5.png" alt="" title="dropopen5" width="290" height="227" class="size-full wp-image-3140" /></a><p class="wp-caption-text">Same dropdown opened up</p></div>
<p>There's a problem here.  If a user forgets to change the selection, the value will always come back "coach." Not good.  We can make a blank top line with one call back in our controller, like so.</p>
<pre class="brush:php">
$depts = ORM::factory('dept')->find_all()->as_array('dept_id','dept_name');
array_unshift($depts, '' );
$data ['footballdepts'] = $depts;
</pre>
<p>The "array_unshift" adds a blank line at the top of the array, now the output looks like this:</p>
<div id="attachment_3142" class="wp-caption alignleft" style="width: 300px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/06/dropunopenblank5.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/06/dropunopenblank5.png" alt="" title="dropunopenblank5" width="290" height="80" class="size-full wp-image-3142" /></a><p class="wp-caption-text">With a blank line in the form</p></div>
<div id="attachment_3143" class="wp-caption alignright" style="width: 300px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/06/dropopenblank5.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/06/dropopenblank5.png" alt="" title="dropopenblank5" width="290" height="251" class="size-full wp-image-3143" /></a><p class="wp-caption-text">Opened up</p></div>
<p>Here's what the array looks like after the array_unshift($depts, '' ) call.</p>
<div id="attachment_3165" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/06/droparrayunshift5.png"><img src="http://www.geekgumbo.com/wp-content/uploads/2011/06/droparrayunshift5.png" alt="" title="droparrayunshift5" width="600" height="165" class="size-full wp-image-3165" /></a><p class="wp-caption-text">After array_unshift</p></div>
<p>Just what we want.  </p>
<p>One gotcha when using array_unshift is that the keys in your array are renumbered, and may no longer match the database id's.  Make sure to check your array keys after using array_unshift().  If your lookup table keys are in sequential order, this should not be a problem.  If not, to get a blank line at the top of the dropdown, you have basically four options:</p>
<p>(1)You can use array_unshift, and make the key translation back in the "searchcriteria' controller when getting your data back from $_POST['theDept'] with a conditional. This is good for when only one or two keys change, and will never change again.  </p>
<p>(2)You can use associative keys in your array, they are not reset when using array_unshift.  This creates a lot of work with database updates and primary keys.  I don't recommend this approach.</p>
<p>(3)You can NOT use the "as_array" method, just use find_all(), and create the array with a foreach loop.  Before entering the foreach loop, create an array variable with a "0 => '' " for the first row, see below for an example.  </p>
<p>(4)Finally, from a comment from one of our readers, Tomek Sulkowski.  You can _add_ a new array with this empty element to the found array.  The trick is to really add it with a "+" sign, not merge (array_merge also sorts keys). So:<br />
$depts = array(0 => '') + $depts;</p>
<p>The "as_array" method in the ORM call will only set up one column.  If you want, for example, "first name (space) last name" outputted in one column, or if you need to put a blank row at the top of the array, you'll have to use a foreach loop, like so.</p>
<pre class="brush:php">

$users = ORM::factory('user')->order_by('fname')->find_all();
// Put a blank row at the top of the array
$oneuser = array(0 => '');
// Create the array from the objects
foreach($users as $user)
	{
	$oneuser[$user->user_id] = "$user->fname  $user->lname";
	}
// Send the data to the view
$data ['userarr'] = $oneuser;
</pre>
<p>If you really want to get fancy, you can create a drop down with one line of code in your view file, like this:</p>
<pre class="brush:php">

Form::select('theDept', ORM::factory('dept')->find_all()->as_array('dept_id','dept_name'));
</pre>
<p>One line of code, and with a lazy load, you've got your select list done.  It can't get much easier than that.</p>
<p>If you would like to use the NewChk application to check your arrays in Kohana 3, <a href="http://www.newchk.com/">download NewChk</a>, drop the chk.php class file in your application/classes directory, and it will be autoloaded and available throughout every file in your application with a simple one line call.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2011/06/26/kohana-3-orm-creating-a-form-select-list/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Announcing NewChk &#8211; a free PHP variable checker</title>
		<link>http://www.geekgumbo.com/2011/06/14/announcing-newchk-a-free-php-variable-checker/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=announcing-newchk-a-free-php-variable-checker</link>
		<comments>http://www.geekgumbo.com/2011/06/14/announcing-newchk-a-free-php-variable-checker/#comments</comments>
		<pubDate>Wed, 15 Jun 2011 03:44:56 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Debugging]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=3112</guid>
		<description><![CDATA[I just finished a new variable checker program for PHP web developers that I am releasing for free to the open source community under the GNU Lesser General Public License. NewChk will check any variable, or PHP global variable, with &#8230; <a class="more-link" href="http://www.geekgumbo.com/2011/06/14/announcing-newchk-a-free-php-variable-checker/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just finished a new variable checker program for PHP web developers that I am releasing for free to the open source community under the GNU Lesser General Public License.</p>
<p>NewChk will check any variable, or PHP global variable, with one simple call in your PHP development file, and then output the result in a CSS formatted output with additional information when the page URL is brought up in your web browser.  It is meant as a replacement for print_r, var_dump, and the multiple echo commands that PHP developers tend to use.</p>
<p>Here is a look at the output from an object, as an example.</p>
<div id="attachment_3120" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.geekgumbo.com/wp-content/uploads/2011/06/chkobj35.png"><img class="size-full wp-image-3120" title="chkobj35" src="http://www.geekgumbo.com/wp-content/uploads/2011/06/chkobj35.png" alt="" width="600" height="365" /></a><p class="wp-caption-text">An object output</p></div>
<p>The entire NewChk program was designed to be self-contained in one file for ease of use.  It is an object-oriented class, that requires PHP 5.2 or higher to run.</p>
<p>If you would like to download the file, and use NewChk, I've put together a web site that includes documentation at <a href="http://www.newchk.com">www.newchk.com</a>.</p>
<p>Comments, bugs, and feedback are appreciated, and can be done through the comment boxes on the newchk web site.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2011/06/14/announcing-newchk-a-free-php-variable-checker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

