<?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</title>
	<atom:link href="http://www.geekgumbo.com/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>Fri, 24 May 2013 13:17:06 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>PSR-2 Coding Style Guide</title>
		<link>http://www.geekgumbo.com/2013/05/19/psr-2-coding-style-guide/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=psr-2-coding-style-guide</link>
		<comments>http://www.geekgumbo.com/2013/05/19/psr-2-coding-style-guide/#comments</comments>
		<pubDate>Sun, 19 May 2013 14:24:33 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[Naming Standards]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=5144</guid>
		<description><![CDATA[The PSR-2 Coding Style Guide is an extension of PSR-1, which I reviewed in my last post.  The PSR standards were created and agreed to by a diverse group of PHP framework and library developers, so that all frameworks and &#8230; <a class="more-link" href="http://www.geekgumbo.com/2013/05/19/psr-2-coding-style-guide/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.geekgumbo.com/wp-content/uploads/2013/05/php.jpeg"><img class="alignleft size-full wp-image-5126" alt="php" src="http://www.geekgumbo.com/wp-content/uploads/2013/05/php.jpeg" width="225" height="225" /></a>The PSR-2 Coding Style Guide is an extension of PSR-1, which I reviewed in my last post.  The PSR standards were created and agreed to by a diverse group of PHP framework and library developers, so that all frameworks and libraries will be able to be used together with the same syntax.</p>
<p>PSR-1 laid out basically three naming conventions: 1. Classes should be named using StudlyCaps or upper Camel case, like so: class BlueMoon{}, 2. methods in the classes should be named in lower camel case, like so: public function setTime(), and 3. constants should be named with caps in snake case, like so: const VERSION_NUMBER =.</p>
<p>Let's expand this with PSR-2 which delves into how to style PHP code. This standard has been much needed to make all code easier to read and understand, and to let PHP developers know how their code should be styled. Here we go:</p>
<p>1. <span style="color: #0000ff;">INDENT</span> - Indent 4 spaces, not tabs.  The problem with tabs is when you go from developer to developer, tabs are different, and the code doesn't line up properly.  In most modern IDEs, you can set tabs to convert to spaces automatically. The 4 spaces is curious, since I've mostly used 3, but from my perspective I'm glad we finally put a stake in the ground.</p>
<p>2. <span style="color: #0000ff;">LINE LENGTH</span> - No hard limit on line length, the soft limit is 120 characters, however you should try to keep your lines under 80 characters for easier reading.  Don't leave a blank space at the end of the line after the semicolon, and of course, only one statement per line.</p>
<p>3. <span style="color: #0000ff;">NAMESPACE</span> - Use one blank line after a namespace declaration, and a blank line after a single or group of USE declarations.  The namespace must be the first line in the file after the PHP tag.  This makes developers more easily aware that the code is within a particular namespace or is using a particular alias for that namespace.  Here's an example:</p>
<pre class="brush:php">namespace Vendor\Package;

use PrintInterface;
use TextClass as TC;
use Vendor2\ORM3\OrmHandler;

class SetUpPrint extends TC implements PrintInterface
{
    ...Do something
}</pre>
<p>4. <span style="color: #0000ff;">CLASS</span> - Opening braces for classes MUST go on the next line, and the closing brace must be on a line of its own at the end.   YEA!, I've been fighting Kerrigan for years, and since I code this way, I'm a happy camper.  After the closing brace of the class leave one blank line.</p>
<p>The class keyword should be in lower case.</p>
<p>Extends and implements keywords must be declared on the same line as the class.  If there is a list of implements you can put them each on a line below the class indented.</p>
<p>Omit the closing PHP tag if the file contains all PHP code.  This one has tripped up many a developer with blank lines after the closing PHP tag throwing an error.</p>
<p>Here's two examples:</p>
<pre class="brush:php">
class SetUpPrint extends TC implements PrintInterface
{
    ...Do something
}

class SetUpPrint extends TextClass implements
    \PrintInterface
    \FontInterface
    \Internationlization
{
    ... Do something
}</pre>
<p>5. <span style="color: #0000ff;">METHOD</span> - Opening braces for methods must go on the next line, and a separate line for the closing brace. Yea! again.</p>
<p>Parenthesis should butt up against the method name with no spaces, and there should be not be a space after the open parenthesis or before the closing parenthesis.</p>
<p>Visibility or scope, like public, protected, and private must be declared on all methods.  The order of declaration should be abstract and final, visibility, and last static before the function keyword.</p>
<p>Method names must not start with an _ .  This can cause some confusion with __contruct type or other PHP magic constants.</p>
<p>Method arguments: commas should have a space after the comma, but none before the comma.  Arguments can be put on multiple lines but they must be indented. If multiple lines are used for arguments, the opening parenthesis is on the method line, and closing parenthesis and the opening method brace are on the same line.</p>
<p>Here's the example:</p>
<pre class="brush:php">

class SetUpPrint extends TC implements PrintInterface
{
    final public static function cannedText($arg1, $arg2, $arg3)
    {
        private $count = 0;
        public  $team_id = null;

        ... Do something
    }

    private function calculateRate(
        $arg1,
        $arg2,
        $arg3
    ) {

        ... Do Something

    }
}
</pre>
<p>The second method is harder to read, but every once and awhile is needed.</p>
<p>6. <span style="color: #0000ff;">CLOSURE</span> - For the most part closures have the same styling as methods with these differences:</p>
<p>Closures must have a space after the function keyword.</p>
<p>When used with the use keyword, there should be a space before and after the use keyword.</p>
<p>Here's the example:</p>
<pre class="brush:php">
$closureRouting = function ($arg1, $arg2) {
    ... Do something
};

$closureRouting2 = function () use ($var1, $var2) {
    ... Do something
};
</pre>
<p>7. <span style="color: #0000ff;">PROPERTY</span> - Declare a visibility on all properties.</p>
<p>Never use the var keyword, this is used with  JavaScript and would cause some confusion.</p>
<p>Use one property per statement instead of chaining properties on one line.</p>
<p>No underscores before the property name, like $_income, instead use $income.  The underscore was used in some frameworks and can be confused with PHP magic variables.</p>
<p>Not this:</p>
<pre class="brush:php">    private $count = $_items = 0;
    public  $_guide_id = $team_id = '';</pre>
<p>Instead, like this:</p>
<pre class="brush:php">    private $count = 0;
    private $items = 0;
    public  $guide_id = null;
    public  $team_id = '';</pre>
<p>6. <span style="color: #0000ff;">CONTROL</span> - Control structures, like IF, WHICH, FOR, and FOREACH must have one space before the condition parenthesis.</p>
<p>The parenthesis should not have a space after the opening parenthesis or a space before the closing parenthesis.</p>
<p>The opening brace should have one space after the closing parenthesis and go on the same line, oh well I can't win them all.</p>
<p>The structured body should be indented.</p>
<p>The closing brace should have a line of its own.</p>
<p>Here are some examples of several control structures:</p>
<pre class="brush:php">if ($i == 1) {
    Do something;
} elseif ($i == 2) {
    Do something else;
else {
    Do a third thing;
{

for ($i = 0; $i &lt; 10, $i++) {
    ... Do something;
}

foreach ($condition as $key =&gt; $value) {
    ... Do something
}

try {
    ...Do something, and throw some errors
} catch    (firstError $e) {
    ... Do something with the error
} catch (secondError $e) {
    ... Do something else with an error
}</pre>
<p>8. <span style="color: #0000ff;">SWITCH</span> - The case keywords should be indented from the switch keyword. There should be a line between each case block with the exception of the first case.</p>
<p>Inside the case, the break keyword should be indented with the rest of the code in the case body.</p>
<p>There must be a comment, such as "// No break" when a fall-through is intentional in a non-empty case, like so:</p>
<pre class="brush:php">switch ($condition) {
    case 0:
        echo 'The condition is 0';
        break;

    case 1:
        echo 'The condition is 1. ';
        // No break

    case 2:

    case 3:

    case 4:
        echo 'The condition has been set';
        return;

    default:
        echo 'No condition was set';
        break;
}</pre>
<p>9. <span style="color: #0000ff;">KEYWORD</span> - Here's one that I'm guilty of.  Keywords, like true, false, and null show be in lower case.  I've always put them in upper case for visibility, not anymore.  They should be set up like so:</p>
<pre class="brush:php">if ($turn == true) {
    Do something;
} elseif ($turn == false) {
    Do something else;
else {
    Do a third thing;
{</pre>
<p>That's it for PSR-2.  It is interesting to note that this style guide isn't just one developer's view of the world, which has been the problem with all the other style guides. The way this standard was developed was to poll all the members of FIG as to each coding style to determine the preference of a majority of the members, considering that the members of FIG cover a broad spectrum of PHP development, these coding styles should be considered not only a standard, but what the PHP community wants to see when reading code.  Thus a developer should strive to code with this style, knowing it is what other developers are expecting.  Thus a standard is born.</p>
<p>As an aside, in both NetBeans and Eclipse you can set up this style in the editor, and then hit a key sequence, and your selected code will be formatted to this style, nice.</p>
<p>To configure the format in NetBeans, go to Tools-&gt;Options-&gt;Editor-&gt;Formatting. You can set the indents for all languages. To set the rest of the style, click the PHP drop down under "Language:" and then in "Category:" drop down you can set the rest of the styles. Once formatting is set in NetBeans, all you have to do is select the code you want to format, and do an Alt-Shift-F and presto your code is formatted. I find I use this a lot while coding to keep my code looking good.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2013/05/19/psr-2-coding-style-guide/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PSR-1 Basic Coding Standard</title>
		<link>http://www.geekgumbo.com/2013/05/12/psr-1-basic-coding-standard/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=psr-1-basic-coding-standard</link>
		<comments>http://www.geekgumbo.com/2013/05/12/psr-1-basic-coding-standard/#comments</comments>
		<pubDate>Mon, 13 May 2013 01:21:29 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[Naming Standards]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=5123</guid>
		<description><![CDATA[With the explosion in PHP frameworks and PHP libraries that has occurred over the last couple of years, developers have started to be concerned about standards for coding that can be used across all frameworks.  To this end, at the &#8230; <a class="more-link" href="http://www.geekgumbo.com/2013/05/12/psr-1-basic-coding-standard/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.geekgumbo.com/wp-content/uploads/2013/05/php.jpeg"><img class="alignleft size-full wp-image-5126" alt="php" src="http://www.geekgumbo.com/wp-content/uploads/2013/05/php.jpeg" width="225" height="225" /></a>With the explosion in PHP frameworks and PHP libraries that has occurred over the last couple of years, developers have started to be concerned about standards for coding that can be used across all frameworks.  To this end, at the php|tek conference in 2009, a group was established called, the PHP Standards Group, which later became the "Framework Interoperability Group", or FIG.</p>
<p>FIG members include many of the most popular frameworks and libraries, like: Zend, Symfony, Lithium, Laravel, PEAR, Composer, phpDocumentor, Drupal, Joomla, Propel, and Doctrine to name a few.  You get the idea.  Each of these frameworks and libraries had their own code, and developers wanted to make sure it all played well together.</p>
<p>To date, FIG members have agreed on four standards that they have labeled PSR-0 to PSR-3.      PSR-0 is an Autoloading Standard, PSR-1 is a Basic Coding Standard, PSR-2 is a Coding Style Guide, and PSR-3 is a Logger Interface, which sets up a Syslog protocol.</p>
<p>The FIG group is gradually becoming a major force in PHP that will dictate how all PHP developers should code for interoperability, thus it behooves all PHP devleopers to pay attention to and code using the PSR standards.  With that in mind, I thought it would be worth while to gradually review these standards.</p>
<p>We'll start with PSR-1 the Basic Coding Standard.  This standard is meant to be a minimum requirement for interoperability between frameworks, so it is relatively short.</p>
<p>1. Only use &lt;?php ?&gt; and &lt;?=  ?&gt; starting and ending tags, and not any other variations.<br />
To avoid interoperability problems in the past frameworks and libraries had been making different starting tags, this avoids the problem.</p>
<p>2. Only use UTF-8 with out any BOM, or byte-order-marking.<br />
The Unicode standard permits byte-order-marking with UTF-8.  Its purpose was to signal the start of the text string with the proper encoding.   One of the main reasons for BOM was legacy encoding, and one of the major drawbacks was it can interfere with pattern matching.  For interoperability, it is best to ensure no BOM is used, and to standardize on UTF-8.  It  means not having to worry about different encoding across frameworks.</p>
<p>3. Namespaces and Classes must follow the PSR-0 standard.<br />
This is for ease of autoloading. We'll cover this in a post on PSR-0. Mostly it means each class is in a file by itself and has a namespace.</p>
<p>4. Class names must be declared in StudlyCaps.<br />
There are two base naming conventions, Snake_Case, and camelCase.  Snake case connects words with underscores, like so: mail_label, or Mail_Label.  CamelCase separates words with capital letters.  CamelCase comes in two forms lower camel case, called camelCase, and upper camel case, or StudlyCaps.  The upper and lower refer to the first letter of the name, thus class names should not be : class codeGenerator, and instead should be: class CodeGenerator with the first letter capitalized.</p>
<p>5. Method names must be declared in camelCase, like: public function getFirstName();</p>
<p>6. Class constants must be declared in all upper case with an underscore separator when needed, like so: const VERSION = 5.3; and const VERSION_DATE = '2013-05-11';.</p>
<p>7. Lastly PSR-1 specifies that classes "should" either not have side effects or have side effects but not mix them in a class with one class to a file.</p>
<p>Side effects is doing other functionality not related to the declaring class, usually done by including files in the class.  Side effects means things like generating output, connecting to external services, modifying ini settings, emitting errors or exceptions, modifying global or static variables, reading from or writing to a file, and so on. This is difficult to do in some cases and is more a guideline, or something to strive for rather than a standard.</p>
<p>The <a title="PSR-1 Coding Standard" href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md">PSR-1 standard is described on github</a>.   If your interested in following the group, or becoming a member,  here is the <a title="FIG Web Site" href="http://www.php-fig.org/">FIG web site</a>.   The group currently has a proposal to add to the PSR-0 standard some refinements, specifically on how to handle underscores in class names, and the group is currently looking at caching.</p>
<p>To cut to the essentials, and sum up,</p>
<p>class names should look like: <span style="color: #0000ff;">class DarkSide{}</span>,</p>
<p>methods like: <span style="color: #0000ff;">public function setDormLights()<span style="color: #000000;">,</span></span> and</p>
<p>constants like: <span style="color: #0000ff;">const SERVER_NAME</span> = ...</p>
<p>We'll cover the other PSR standards in future posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2013/05/12/psr-1-basic-coding-standard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A PHP Singleton Flip-Flop, TRUE or FALSE</title>
		<link>http://www.geekgumbo.com/2013/04/26/a-php-singleton-flip-flop-true-or-false/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=a-php-singleton-flip-flop-true-or-false</link>
		<comments>http://www.geekgumbo.com/2013/04/26/a-php-singleton-flip-flop-true-or-false/#comments</comments>
		<pubDate>Fri, 26 Apr 2013 14:53:40 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=5093</guid>
		<description><![CDATA[When I was learning computer internals, the hardware logic component that was the foundation of the computer was the flip-flop. The flip-flop was an electrical circuit that was either a one or zero. That usually translated to +9 volts or &#8230; <a class="more-link" href="http://www.geekgumbo.com/2013/04/26/a-php-singleton-flip-flop-true-or-false/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.geekgumbo.com/wp-content/uploads/2013/04/flip-flop2-225.jpg"><img class="alignleft size-full wp-image-5118" alt="flip-flop2-225" src="http://www.geekgumbo.com/wp-content/uploads/2013/04/flip-flop2-225.jpg" width="225" height="166" /></a>When I was learning computer internals, the hardware logic component that was the foundation of the computer was the flip-flop. The flip-flop was an electrical circuit that was either a one or zero. That usually translated to +9 volts or 0 Volts. In computer software, we call this a BOOLEAN, they're either set to TRUE or FALSE. After all, we do live in a digital, thus binary world. Let's have some fun with a couple of puzzles that deal with a BOOLEAN, true or false.</p>
<p>The other day, I was happily coding away, and ran into a little conundrum. I had created an event that fired globally after every save in my web application. The event allowed me to write additional code to alter some values depending on where in the application the user had saved his form, and then re-save the changed values back to the database. Everything went along swimmingly until I saved in my added code. Whereupon I looped around several hundred times, and hung my system, a good reason, to always do your coding on your local computer. Yep, you guessed it, my save in my additional code, triggered the global event that happened on every save, which triggered the save in my added code, and around and around we went until we stopped only where Apache knows.</p>
<p>Hmm, what to do to stop the loop? This is the pregnant pause that allows you to come up with a solution until I tell you mine.</p>
<p>Got it, well in pseudocode speak, here's how to stop the looping.</p>
<p><span style="color: #0000ff;">The event triggers on a user's save.</span><br />
<span style="color: #0000ff;"> You set a "$flag" variable to TRUE initially to tell the additional code to run the first time.</span><br />
<span style="color: #0000ff;"> You check to see if $flag is set to TRUE, if so run the added code.</span><br />
<span style="color: #0000ff;"> Right before you save in your added code, you set the $flag variable to FALSE.</span><br />
<span style="color: #0000ff;"> When you save your additional code, it fires the global save trigger.</span><br />
<span style="color: #0000ff;"> You go back to your additional code, and this time the $flag variable is set to FALSE</span><br />
<span style="color: #0000ff;"> You set $flag variable to TRUE, and return out of the added code without running it.</span></p>
<p>Simple! Not so fast. The $flag variable is a simple BOOLEAN, it's either TRUE of FALSE. How do we save our "$flag" variable on our system? The second pregnant pause for you to come up with a solution.</p>
<p>OK, let's go through our options.</p>
<p>1. We save the $flag variable locally as a private property of our class. Seems like it would work, but the problem here is initializing the variable, since every time you run an instance of the class you reinitialize the variable. Won't work, because if you go to FALSE, it will be reset to TRUE when re-initialized. Hmm...</p>
<p>2. We make a GLOBAL variable. This works, except every time I hear GLOBAL, I cringe. GLOBAL variables are vulnerable to any other coder who changes the variable to something else, or names a variable the same in their code, they are not exclusive. One of the reasons that "namespace" came into being. Since I work with a bunch of developers, who all work on the same application, and the application runs on a government, highly secure computer, I shy away from the GLOBAL variable. I do not have exclusive control of a GLOBAL. Let's find something else.</p>
<p>3. A $_SESSION variable. This works. My problem here is the flaky way new versions of browsers are handling variables created locally, and on a government web site, your not sure how long session variables are maintained, or how they are treated. It works, but less than ideal.</p>
<p>4. Use a Singleton. This works, and is the solution I choose, and will cover in the rest of this article. The singleton has the advantage in that it is accessible globally, but you need to call the class to get the private variable, and only one instance of the variable can exist, not multiple values that might occur with GLOBAL variables.</p>
<p>The reason for this article is to give you, my readers, a template for a TRUE or FALSE, flip-flop, singleton you can use in your own code anytime you need a BOOLEAN global variable. Here's the code:</p>
<pre class="brush:php">/**
 * A singleton used as a secure BOOLEAN global variable
 * 
 * @param BOOL $flag  can only be TRUE or FALSE
 */
class saveFlagSingleton 
{
   private $flag; 
   private $defaultFlag = TRUE;
   private static $FlagObject = NULL;  // stores the instance of the object that stores $flag

// Only initiate the object within this class, "new" will not generate an instance outside this class
private function __construct() {}

// Prevent any copying or cloning of object
private function __clone() {}

// One instance only, generate the object to hold the variable
public static function getFlagObject()
{
   // Does the object already exist? If not make a new instance of the class
   if (empty(self::$FlagObject ))
   {
       self::$FlagObject = new saveFlagSingleton();
   }
   $FlagObj = self::$FlagObject;
   return $FlagObj;
} 

// Get current $flag setting
public function getFlag() 
{
   // if the Flag is empty, assign the default value
   if (empty($this-&gt;flag))
   {
      $this-&gt;flag = $this-&gt;defaultFlag; 
   }
   $theFlag = $this-&gt;flag;
   return $theFlag;
} 

// Set the current Flag
public function setFlag($setFlag)
{
   $this-&gt;flag = $setFlag;
}
} // End class</pre>
<p>Only 47 lines of code with comments, and once you have this template, you can drop it in a file, and then call it when ever you need a global BOOLEAN.</p>
<p>Let go through the code, real quick. The variables are: $flag, a property of the object, which is where the current state of the TRUE or FALSE will reside. $flag is a private variable, so you have to use a method to access it, in the one, and only one, instance of the saveFlagSingleton class. The one instance of the class is called $FlagObject. There is a $defaultFlag variable used as a default value to initialize $flag.</p>
<p>OK, we have the singleton set up that we can drop into our code, how do you use it?<br />
In your code, where you want to use a global TRUE or FALSE, first you have to include the class, like so:</p>
<pre class="brush:php">require_once "saveflagsingleton.php";</pre>
<p>We start through our code, and want to see if we will run our added code, or not, like so:</p>
<pre class="brush:php">// This stops you from running the added code if $flag is set to FALSE
// Get the current flag state
$flag = saveFlagSingleton::getFlagObject()-&gt;getFlag();

if ( $flag === FALSE )
{
   $flag = TRUE;
   // Set the current Flag state back to TRUE for the next run
   saveFlagSingleton::getFlagObject()-&gt;setFlag($flag);
   // Return to bypass the added code
   return;
}</pre>
<p>Now at the bottom of your added code, right before the added code save, we want to set the Flag back to FALSE so when the global event fires and starts through the added code again it will encounter a FALSE and won't run. Here goes:</p>
<pre class="brush:php">// Stop global event from firing again 
$flag = FALSE ;
saveFlagSingleton::getFlagObject()-&gt;setFlag($flag);

// Now do the added code save</pre>
<p>Well, as Bugs Bunny would say, "That's All Folks," or was that Elmer Fudd? Happy coding!</p>
<p><a href="http://www.geekgumbo.com/wp-content/uploads/2013/04/elmer.jpg"><img class="aligncenter size-full wp-image-5108" alt="elmer" src="http://www.geekgumbo.com/wp-content/uploads/2013/04/elmer.jpg" width="259" height="194" /></a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2013/04/26/a-php-singleton-flip-flop-true-or-false/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vacationing with the new Nook HD</title>
		<link>http://www.geekgumbo.com/2013/04/09/vacationing-with-the-new-nook-hd/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=vacationing-with-the-new-nook-hd</link>
		<comments>http://www.geekgumbo.com/2013/04/09/vacationing-with-the-new-nook-hd/#comments</comments>
		<pubDate>Wed, 10 Apr 2013 02:11:32 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[eReaders]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=5055</guid>
		<description><![CDATA[It seems like every vacation I end up with a new eReader.  The eReader vendors are doing a good job at improving their products, marketing, and pricing their new features so you are willing to put out the bucks for &#8230; <a class="more-link" href="http://www.geekgumbo.com/2013/04/09/vacationing-with-the-new-nook-hd/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="attachment_5064" class="wp-caption alignleft" style="width: 125px"><a href="http://www.geekgumbo.com/wp-content/uploads/2013/04/nook-hd250-3.jpg"><img class=" wp-image-5064     " alt="The new Nook HD with color menu" src="http://www.geekgumbo.com/wp-content/uploads/2013/04/nook-hd250-3.jpg" width="115" height="176" /></a><p class="wp-caption-text"><br />The new Nook HD<br />with color menu</p></div>
<p>It seems like every vacation I end up with a new eReader.  The eReader vendors are doing a good job at improving their products, marketing, and pricing their new features so you are willing to put out the bucks for the new version.  And they do make for very nice Christmas presents, not hard to pick out, and something everyone likes.  Thus, I received a new Nook HD for Christmas, started using it, and took it on my vacation to Jamaica.</p>
<p>The Nook HD has a high resolution 7" color screen.  I've noticed that eInk or color eInk has disappeared from the listed features.  It's like you shouldn't worry about the screen any more, but of course, I do.</p>
<p>This little tablet is really a computer, running the Android 4.03 operating system, allowing you to download and run your favorite apps.  It has 13Gb for storing your books or movies.  Books run from 100 to 300Mb, with 300Mb being about 800 pages.  That means, using an average of 250Mb per book, you can store about 52 books on the Nook before you have to archive back to Barnes and Nobles drive, plenty of space.  It has built-in WiFi and Bluetooth connectivity, and yes although only a 7" screen, you can surf the Internet, and send emails just like with a laptop.  I did mention that it has a high resolution of 243 pixels per inch with 16 million colors, which means NetFlix movies look good on the screen, the colors are gorgeous, and the audio comes with dual stereo speakers, volume control buttons, and headphone jacks, even a built in microphone if you want to dictate your next novel.  It's battery is rated at 10.5 hours reading and 9 hours playing videos.  Ok, we've established that the 7.7"x 5" Nook HD is a small 11.1 ounce computer with WiFi.</p>
<p>The new Nook is lighter and thinner than the old Nook and nice to hold in your hand.  We stayed at a hotel that advertised free WiFi.  I sometimes bring my laptop with me on vacation, but why did I need to take my laptop?  I had the Nook HD.  My answer was, I didn't, and I left it at home with out any problems from it not being there.  I wasn't going to work on vacation anyway, so I didn't need a keyboard, and for surfing the Internet, the on-screen keyboard works fine.  What else I didn't have to do was lug the normal five, or six trash novels I read in a week at the beach, they were all safely residing in my Nook.</p>
<div id="attachment_5061" class="wp-caption alignleft" style="width: 154px"><a href="http://www.geekgumbo.com/wp-content/uploads/2013/04/readernook250.jpeg"><img class=" wp-image-5061    " alt="readernook250" src="http://www.geekgumbo.com/wp-content/uploads/2013/04/readernook250.jpeg" width="144" height="196" /></a><p class="wp-caption-text"><br />The old Nook</p></div>
<p>Since my prior vacations were with the original eInk Nook, and I've waxed on in a couple of articles about color eInk being the next new technology, boy was I wrong about that, it's worth doing a little comparison, since I have spent over a week, or so, using both Nooks over 10 hours a day.  On vacation, I tend to vegge out on the beach, under a canopy, and read all day, while I'm picking up those warm rays, dangling my feet in the warm sea, and watching the woman go by in their string bikinis, life is good.</p>
<p>I digress, OK, so the first thing that stood out, and I couldn't help but notice about the new Nook, was the touch screen.  Wow, it is extremely sensitive and responsive, at times I thought maybe a little too sensitive.  If you compare it to the original Nook, which had a little touch color window at the bottom, the touch sensitivity has improved 10 fold for the better, and the entire screen is touch sensitive, not just a little screen at the bottom.   And since the entire screen is touch sensitive, navigation is easier as you can hyperlink to each chapter and jump back and forth.</p>
<p>The page flipping buttons are gone from the old Nook.  To be honest, after flipping pages continually all day by pressing a button on the old Nook, I found my thumb getting a little sore.  On the new Nook it is done using the touch screen.  You can either swipe like your turning the page on a real book, or tap a side of the screen to turn the page.  This led to some problems when I would accidentally touch the screen and the page would flip.  I wasn't sure if I had tapped the left side to go back, or the right side to go forward.  Sometimes the pages flipped a couple of times which was confusing.  To find out where I was in the book, I had to flip back and forth to find the paragraph I was reading.  I have to admit this was annoying at times, and I found myself trying to be real careful on how I was holding the Nook while I was reading or changing body positions.</p>
<p>What I found disconcerting, at first, while I was reading was the screen kept changing directions.  The new Nook has automatic page orientation depending on how you hold the Nook.  You can hold the Nook horizontally, and have more words across the page, which is just like a normal book, and is pleasant way to read, or if you change the orientation of the Nook to vertical, the Nook will automatically switch the direction of the page.  You can actually spin the Nook a full 360 degrees and the eReader will orient the page on the fly as you turn the Nook.  That was neat at first, but as I flopped around changing my body orientation the Nook would sometimes flip the page when I didn't want it to.  This drove me nuts for a day or so until I realized by simply bringing up a menu with one touch, I could turn off the automatic orientation and freeze the page to one orientation, much better.</p>
<p>And now to what you all want to know.  How was the screen in sunlight?  The old Nook was superb in sunlight, eInk technology was made for sunlit screens, and the old Nook was a joy to read in the sun.  The letters just lit up.  The new Nook not so much so.  I found that in the sunlight I had to increase the brightness to maximum to be able to read.  It was easy to change the brightness, you touch the little menu icon at the top of the screen, the menu pops up, and you slide the brightness to max with a slider control.  But that maximum brightness you use in the sunlight was too bright for the hotel room and I had to turn it down.  I have to rate the old Nook better in the sun, of course.  But the old Nook didn't have a color screen, more a dull grey eInk screen, while the new Nook has a back-lit white screen.  The letters stand out more on the white screen, but are harder to see in the sun, because of that bright whiteness.  Now, to be honest, I was under a canopy, not in direct sun, and once I put the brightness to the maximum, I didn't have a problem reading.</p>
<div id="attachment_5072" class="wp-caption alignleft" style="width: 235px"><a href="http://www.geekgumbo.com/wp-content/uploads/2013/04/nookhd4-250.jpg"><img class=" wp-image-5072  " alt="Nook HD open    to a book" src="http://www.geekgumbo.com/wp-content/uploads/2013/04/nookhd4-250.jpg" width="225" height="316" /></a><p class="wp-caption-text"><br />Nook HD open<br />to a book</p></div>
<p>Pushing up the brightness during the day led to another problem, the battery.  I could gradually watch the battery go down with max brightness.  I could still spend a good seven or eight hours without a problem, but I was more battery conscience than with the old Nook, and found myself plugging the Nook into the USB power adapter every time I went back to the room.  The new Nook has a wider power connector where it hooks to the Nook and I found myself wishing it had the same power jack as the old Nook and my cell phone.  This meant carrying two power cables on vacation.  I had previously purchased a two USB-to-wall socket adapter, so I able to charge each device at the same time.  Although the battery was a worry, I never really had a problem with running out of power.</p>
<p>To wrap this up, the old Nook seems like an old friend that I spent many hours enjoying, and I still know its there, just in case, but the new Nook gradually won me over.  Since I have both, and I still read on both, which one would I take on my next vacation, that's easy, the new Nook.  Yes, it has its quirks, which I talked about in this article, but they were quirks that I got use to.  What eventually won me over was the way the new Nook felt in my hand.  The quality of the print on the page.  The overall quality of the product.  The ease of use of the menu system with the touch screen across the entire screen, not just a small window.  The ease of browsing on the web.  In the end, I just liked the new Nook better.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2013/04/09/vacationing-with-the-new-nook-hd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Amazon Changes My Buying Habits, Again</title>
		<link>http://www.geekgumbo.com/2013/04/02/amazon-changes-my-buying-habits-again/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=amazon-changes-my-buying-habits-again</link>
		<comments>http://www.geekgumbo.com/2013/04/02/amazon-changes-my-buying-habits-again/#comments</comments>
		<pubDate>Tue, 02 Apr 2013 22:37:31 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[Editorials]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=5032</guid>
		<description><![CDATA[Amazon became the gorilla in Internet retailing by operating at a loss for many years while it was getting started. They offered discount prices, gradually made an easy to use web site, added user reviews, worked hard at getting the &#8230; <a class="more-link" href="http://www.geekgumbo.com/2013/04/02/amazon-changes-my-buying-habits-again/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.geekgumbo.com/wp-content/uploads/2013/03/amazon225.jpeg"><img class="alignleft size-full wp-image-5045" alt="amazon225" src="http://www.geekgumbo.com/wp-content/uploads/2013/03/amazon225.jpeg" width="225" height="239" /></a>Amazon became the gorilla in Internet retailing by operating at a loss for many years while it was getting started. They offered discount prices, gradually made an easy to use web site, added user reviews, worked hard at getting the orders correctly and timely to customers, and offered free shipping.</p>
<p>In my mind, it was the free shipping that got them to number one, and in the process forced a lot of businesses to close. I still lament the demise of Borders, which I attribute to people going to Borders, looking through the books to find the exact book they wanted, and then going on-line to buy it cheaper from Amazon with free shipping.</p>
<p>Amazon solidified consumer loyalty with user reviews.  People bought into the idea of letting everyone know what they thought about products.  Consumers gradually gave up on the need to  touch, see, and feel products in stores. Every one started to go to Amazon to find the best product by reading reviews.</p>
<p>Others tried to copy Amazon, but failed. Everyone still went to Amazon for reviews, and then to buy.   Amazon became the place to go for product reviews.  Who wanted to put their reviews on every site on the web.  And by continuing to offer discount prices, and free shipping, Amazon became hugely successful. They became the gorilla of eCommerce.</p>
<p>It's been a couple of years now, but I've noticed a gradual change in Amazon's philosophy.  It started with Amazon prime.  With Amazon prime, Amazon offered free two-day shipping for, I believe, initially $50 per year. It's now $79 a year. Why do this? That was my question when I was getting free shipping, and I was willing to wait a couple extra days.</p>
<p>Interestingly, during this period, I did notice, that either Amazon was opening more shipping centers, or shippers were getting more efficient, because some times items I purchased would start arriving early. Instead of the projected two weeks, it would get to me in one week. No need for Amazon Prime, I was a happy camper.</p>
<p>Not anymore, I'm here to report that Amazon has changed. The bean counters have arrived, and profit is king. Let's start squeezing consumers every where we can.</p>
<p>I don't know if any one else has noticed, but free shipping is pretty much history. It's gone. To be fair to Amazon, it definitely costs more to ship, because of increasing gas prices, but I have noticed that Amazon shipping charges seem high.</p>
<p>I went to purchase a headset from Amazon. I did my careful review, picked out the headset I wanted. The headset was $15.98, Amazon shipping was $8.48. I wanted a picture frame, it cost $12.99, shipping was $8.25, and finally a pair of warm socks cost $19.55, shipping was $8.09. Socks you can put in a small box and ship for $5.00 at the Post Office.  What was worse, if I combined all three items into one order the shipping was the total of all three items individual shipping.   I understand it, but it didn't seem right to me.</p>
<p>That prompted me to compare prices, and what I found was, that in-addition to many online eCommerce sites, brick and mortar stores were cheaper for the same item. I found many stores, like Target and Walmart, and even Macy's lower in price.   From my perspective, that meant that Amazon was raising its prices, and was no longer the place to go for discount prices. They must feel they have consumers locked in, and are now going to turn that into increased profits.  Many stores have started out at discount prices, gained a market share, and then gradually tried to raise their prices, only to lose their market segment, and gradually fail.</p>
<p>Amazon, going forward, may start getting some of the medicine it initially dished out to others, like Borders.  I'm not saying that Amazon is going to close up shop any time soon, but brick and mortar stores can now compete.</p>
<p>They can order in bulk directly, and therefore, their shipping charges will be lower, which means they can offer consumers a lower price and immediate access to products without shipping.</p>
<p>This can only be good for every one, but Amazon. Oh, I'll still go to Amazon for reviews, but now I'll add a couple of extra steps, I'll do a price comparison, and I'll find out if stores near me have the product in stock at a better price. Yes, its a little more effort, but not that much, and I get the product immediately.</p>
<p>In short, in my mind, Amazon has lost its luster. It's now just another eCommerce site.  Admittedly, still my first place to go to research products, but once I make my choice, Amazon is no longer an automatic buy like it use to be.</p>
<p>What stops me from clicking that "Place your order" button, and triggers my search for a better buy is the shipping charge.   No free shipping means I can get a better price somewhere else.   Isn't it ironic,  Amazon trained me to buy on-line by offering free shipping, now they are training me to go elsewhere by taking it away.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2013/04/02/amazon-changes-my-buying-habits-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regular Expression Patterns</title>
		<link>http://www.geekgumbo.com/2013/03/16/regular-expression-quick-look-up/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=regular-expression-quick-look-up</link>
		<comments>http://www.geekgumbo.com/2013/03/16/regular-expression-quick-look-up/#comments</comments>
		<pubDate>Sat, 16 Mar 2013 23:51:24 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=5005</guid>
		<description><![CDATA[This is a quick, look-up of pre-constructed regular expression patterns you can use while validating forms and working with the Internet.  A cheat sheet to speed up your coding.  Each of these has been tested to work with PHP functions. &#8230; <a class="more-link" href="http://www.geekgumbo.com/2013/03/16/regular-expression-quick-look-up/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.geekgumbo.com/wp-content/uploads/2013/03/owl.jpeg"><img class="alignleft size-full wp-image-5042" alt="owl" src="http://www.geekgumbo.com/wp-content/uploads/2013/03/owl.jpeg" width="212" height="237" /></a>This is a quick, look-up of pre-constructed regular expression patterns you can use while validating forms and working with the Internet.  A cheat sheet to speed up your coding.  Each of these has been tested to work with PHP functions.</p>
<p>If you would like to test any of these patterns yourself with an on-line tester,  I recommend the Regular Expression Test Tool, <a title="Regular Expression Testing Tool" href="http://www.solmetra.com/scripts/regex/index.php" target="_blank">located here</a>.  To test, drop the starting and ending quotes in the $pattern variable and paste /../ into the tester.</p>
<p><span style="text-decoration: underline; color: #0000ff;"><strong>Validating Forms</strong></span></p>
<p><strong><span style="color: #008000;">Usernames</span></strong><br />
It's normal to place restrictions on usernames, as opposed to first and last names. This pattern must have 8 to 25 alphanumeric characters, and is allowed to have _ or - between the characters, but no other punctualtion is allowed.  It treats spaces as separate words and will only match words from 8 to 25 characters.</p>
<pre class="brush:php">$pattern ="/[[:alnum:]_-]{8,25}/";</pre>
<p><span style="color: #008000;"><strong>Addresses with PO Boxes</strong></span><br />
Matches: Box or box and that's it.</p>
<pre class="brush:php">$pattern = "/[Bb]ox/";</pre>
<p><span style="color: #008000;"><strong>US Postal Zip Codes</strong></span><br />
Must have 5 digts. and it may have a - with 4 digits, that's it. No other characters allowed.  This will not validate Canadian or UK postal codes.</p>
<pre class="brush:php">$pattern = "/^[0-9]{5}(?:-[0-9]{4})?$/";</pre>
<p><span style="color: #008000;"><strong>Canadian Zip Codes</strong></span><br />
Candian postal codes must have two groups of 3 alphanumerics with a space in the middle.  The first letter may not start with DFIOQUW or Z. A good number is: "K2A 9B3"</p>
<pre class="brush:php">$pattern = "/^[^DFIOQUWZdfioqwz][0-9][[:alpha:]] [0-9][[:alpha:]][0-9]/";</pre>
<p><span style="color: #008000;"><strong>U.K. Postcodes</strong></span><br />
Must have 5-8 alphanumeric characters separated by a space that starts with a letter. Valid codes are: "DN55 1PT" and "B33 8TH" for example.</p>
<pre class="brush:php">$pattern = "/^[[:alpha:]]{1,2}[0-9][[:alnum:]]? [0-9][[:alpha:]][[:alpha:]]/";</pre>
<p><span style="color: #008000;"><strong>North American Phone Numbers</strong></span><br />
Must be 10 digits. Digits can be grouped as 3 3 4 digits and separated with a . - () or spaces. This is a good pattern to use the preg_match_all to separate the numbers into groups.</p>
<pre class="brush:php">$pattern = "/^(\(?[0-9]{3}\)?)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})?/";</pre>
<p><span style="color: #008000;"><strong>Format North American Phone Numbers to a set Format</strong></span><br />
Use preg_replace with the above pattern. If it's a valid number, in this pattern, it is formatted to:  (123) 456-7899</p>
<pre class="brush:php">$replacement = "($1) $2-$3";</pre>
<p><span style="color: #008000;"><strong>International phone numbers</strong></span><br />
International numbers start with a + followed by country code and national number. Must have a +, numbers must be at least 7 digits, and can not exceed 15 digits.</p>
<pre class="brush:php">$pattern = "/^\+(?:[0-9] ?){6,14}[0-9]$/";</pre>
<p><span style="color: #008000;"><strong>Email addresses</strong></span><br />
Before the @, it allows multiple numbers, upper and lower letters, and . _ % - and that's it. You must have a @.  After the @, you must have at least one dot, but not 2 dots together, and the after the final . only 2-6 letters to match both 2 digit country codes and the 6 digit .museam.</p>
<pre class="brush:php">$pattern = "/[A-Za-z0-9._%-]+@(?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,6}$/";</pre>
<p><span style="text-decoration: underline; color: #0000ff;"><strong>Date and Time</strong></span></p>
<p><span style="color: #008000;"><strong>Date Formats</strong></span><br />
Match m/d/yy or mm/dd/yyyy allowing 1 or 2 digits for day and month and 2 or 4 digits for year. This is a good one to use with preg_match_all to pull dates out of the group. This will match years of 4 or 2 digits starting with 00 but not just a single digit for the year.</p>
<pre class="brush:php">$pattern = "/^(1[0-2]|0?[1-9])\/(3[01]|[12][0-9]|0?[1-9])\/(?:[0-9]{2})?([0-9]{2})/";</pre>
<p>If you require leading zeros and a 4 digit year, try this pattern. This requires the format: mm/dd/yyyy.  If you want to see the output of preg_match_all multidimensional array, my <a title="Newchk.com" href="www.newchk.com">newchk utility</a> could help you when you only want a part of the year.</p>
<pre class="brush:php">$pattern = "/^(?:(1[0-2]|0[1-9])\/(3[01]|[12][0-9]|0[1-9])|(3[0-1]||12[0-9]|0[1-9])\/(1[0-2]|0[1-9]))\/([0-9]{4})/";</pre>
<p>If you're searching through text for dates, as opposed to verifying form entries,  you'll need to use the /b word delimiter on each side of the pattern.  That goes for all the rest of these patterns, also.</p>
<pre class="brush:php">$pattern = "/\b(?:(1[0-2]|0[1-9])\/(3[01]|[12][0-9]|0[1-9])|(3[0-1]||12[0-9]|0[1-9])\/(1[0-2]|0[1-9]))\/([0-9]{4})\b/";</pre>
<p><span style="color: #008000;"><strong>Time</strong></span><br />
Hours:Minutes:Seconds for a 24 hour or 12 hour clock.  Preg_match_all can break this into an array where you can pull the hours out.</p>
<pre class="brush:php">$pattern = "/^(2[0-3]|[01]?[0-9]):([0-5]?[0-9]):([0-5]?[0-9])$/":</pre>
<p><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">Security</span></span></strong></p>
<p><span style="color: #008000;"><strong>Passwords</strong></span><br />
A combination of upper and lower case letters and numbers and at least 8 characters, but not more than 25 characters,  No control characters.</p>
<pre class="brush:php">$pattern = "/^(?=.*[[:alnum:]]).{8,25}/";</pre>
<p>And with control characters, but not quotes or | which could lead to SQL injection</p>
<pre class="brush:php">$pattern = "/^(?=.*[[:alnum:]]|[~!@#$%^&amp;*()-_=+]).{8,25}/";</pre>
<p><span style="color: #008000;"><strong>U.S. Currency</strong></span><br />
Make the $ sign and any commas optional. There must be a . with 2 decimals<br />
It will recognize $.90, $0.90, $002,456.23, and $ 23.13 with a space after the $ sign.</p>
<pre class="brush:php">$pattern = "/^\$ ?([0-9]{0,3}(,[0-9]{0,3})*|[0-9]+)(\.[0-9][0-9])$/";</pre>
<p><span style="color: #008000;"><strong>Credit Cards</strong></span><br />
First, use preg_replace to strip out the spaces and -'s between the numbers.</p>
<pre class="brush:php">$pattern = "/[ -]/";
$replacement = '';
$cleanccnumber = $preg_replace($pattern, $replacement, $ccnumber)</pre>
<p>The four major credit card companies (Visa, MasterCard, Discover, Amex) all have different number formats. Visa 16 digits starting with a 4, Mastercard 16 digits starting with 51-55, Discover 16 digits starting with 6011 or 15 digits starting with 5, Amex 15 digits starting with 34 or 37. This checks all these combinations for each type of card.</p>
<pre class="brush:php">$pattern = "/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011)[0-9]{12}|5([0-9][0-9])[0-9]{12}|3(?:[47][0-9]{13}))?/";</pre>
<p><span style="color: #008000;"><strong>Credit Card Security Code</strong></span><br />
Three numbers for all cards, except Amex has four numbers.</p>
<pre class="brush:php">$pattern = "/^[0-9]{3,4}$/";</pre>
<p><span style="color: #008000;"><strong>Credit Card Expire Date</strong></span><br />
Usually are 2 digit month and 2 digit year, but normally done with a drop down menu for validation.</p>
<p><span style="color: #008000;"><strong>Social Security Number</strong></span><br />
Nine digit numbers in the format of 999-99-9999.  The first three digits are not 000, 666, or 900 to 999. The other two groups can not be 00 or 0000.  Everything else works.</p>
<pre class="brush:php">$pattern = "/^(?!000|666|9[0-9]{2})[0-9]{3}-(?!00)[0-9]{2}-(?!0000)[0-9]{4}$/";</pre>
<p><span style="color: #008000;"><strong>Federal Tax ID Number</strong></span><br />
EIN numbers are 9 digit numbers in the format of 99-9999999.</p>
<pre class="brush:php">$pattern = "/[0-9]{2}-[0-9]{7}/";</pre>
<p><span style="color: #008000;"><strong>U.S. Passport Number</strong></span><br />
Must be between six to nine digits all together.</p>
<pre class="brush:php">$pattern = "/^[0-9]{6,9}$/";</pre>
<p><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">Internet</span></span></strong></p>
<p><span style="color: #008000;"><strong>IPv4 Address</strong></span><br />
IP address are 4 groups of 3 digits, between 0 - 255, like so, 255.255.255.255 or theoretically they could be 0.0.0.0</p>
<pre class="brush:php">$pattern =  "/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/";</pre>
<p><span style="color: #008000;"><strong>IPv6 Addresses</strong></span><br />
The new IPv6 addresses consists of eight 16-bit words, as 4 hexadecimal characters each, and delimited by colons. Leading zeros are optional, for example: "1762:1230:EFAC:220:2:B03:1:AF18"</p>
<pre class="brush:php">$pattern = "/^(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}$/i";</pre>
<p><span style="color: #008000;"><strong>Domain Names</strong></span><br />
This will account for both domesitic and international domain names, for example: http://www.geekgumbo.com</p>
<pre class="brush:php">$pattern = "/^(https?|ftp|file):\/\/.+$/i";</pre>
<p>My intent is to gradually add to this list over time.  If any one would like to add a pattern to the list, please put them in a comment, and I will be happy to expand the list for others to use.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2013/03/16/regular-expression-quick-look-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regular Expression Syntax</title>
		<link>http://www.geekgumbo.com/2013/03/10/regular-expressions/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=regular-expressions</link>
		<comments>http://www.geekgumbo.com/2013/03/10/regular-expressions/#comments</comments>
		<pubDate>Sun, 10 Mar 2013 15:19:06 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=4980</guid>
		<description><![CDATA[In our last post I went through a quick overview of the PHP functions that can be used with regular expression patterns.  Let's take a closer look at these patterns. I always assign my reqular expression to a variable, to &#8230; <a class="more-link" href="http://www.geekgumbo.com/2013/03/10/regular-expressions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>In our last post I went through a quick overview of the PHP functions that can be used with regular expression patterns.  Let's take a closer look at these patterns.</p>
<p>I always assign my reqular expression to a variable, to make it easy to change, and use with a function, like so:</p>
<pre class="brush:php">$pattern = "/quick/";

if(preg_match($pattern, $text))
{
... do something
};</pre>
<p>The above reqular expression will find a lower-case quick.  We then use the pattern with a PHP regular expression function like preg_match, <a title="Regular Expression Functions" href="http://www.geekgumbo.com/2013/03/03/php-regular-expression-functions/">see my last article</a>.</p>
<p>Let's talk about this pattern.  The quotes are enclosing the pattern, like you would any string in PHP. The / starts the regular expression and encloses the pattern with the exception that there are some modifiers that you can use after the last /, like so:</p>
<pre class="brush:php">$pattern = "/quick/i"</pre>
<p>The "i" says ignore case, now we would match on either quick or Quick.</p>
<p>If you want to include a / in the pattern, you  can escape the / with a backslash, \ , like so.<br />
/123\/456/  would match 123/456</p>
<p>Let's work through the syntax:</p>
<p>/^ar/     ^  finds a string starting with ar</p>
<p>/ar$/   $  finds strings ending in ar.</p>
<p>/a.r/    .   is like a wild card and matches any one character, here this would match aar, abr, acr, adr, ...</p>
<p>/ab*c/   *   the asterisk means zero or more of the last character.  This matches ac, abc, abbc, abbbc, ...</p>
<p>/do(es)?/  ?  the question mark matches the preceding grouping 0 or 1 time.  This matches do or does.</p>
<p><span style="color: #0000ff;">BRACKETS [   ]</span></p>
<p>Brackets are used to match anything within the bracket.</p>
<p>/ar[ckt]/  matches arc, ark, and art</p>
<p>/[0-9.-]/  matches any number, dot, or - sign</p>
<p>There is an or, |, operator<br />
/[abc|xys]/  matches abc or xys</p>
<p><span style="color: #0000ff;">NOT CHARACTER ^</span></p>
<p>There is a reverse character inside the bracket, ^, which matches anything but the characters given.   This is not at the start of the pattern, and doesn't mean "starts with."  It is inside the brackets.</p>
<p>/ar[^ckt]/  matches ara, arb,ard, ... not arc, ark, or art</p>
<p>/[^A-Za-z0-9]/  matches any symbol not a number or letter</p>
<p><span style="color: #0000ff;">RANGES  -</span></p>
<p>Brackets also allow for ranges.<br />
/ar[c-e]/  matches ar with c,d, or e, that is: arc,ard,are, but not ara, or arf<br />
/[0-9]/    matches any numbers<br />
/[A-Z]/    matches any capital letters</p>
<p>You can combine ranges<br />
/[0-9A-Za-z]/  matches all letters upper and lower case and numbers.  In the ASCII character table capital letters come before lowercase letters and are separate characters.</p>
<p><span style="color: #0000ff;">MULTIPLIERS</span></p>
<p>There's some special characters that act as multipliers.</p>
<p>If you want to do one or more you use a plus, like this:<br />
/ab+c/  matches abc, abbc, abbbc, abbbbc, ...</p>
<p>You can use multipliers with ranges<br />
/[a-z]+/  matches one or more lowercase letters.  For example, searching  "This one" would match "his".</p>
<p>If you want to do 0 or 1 more<br />
/ab?c/  matches ac, abc, and that's it.</p>
<p>You can do a repetive grouping with ( )<br />
/a(bc)+d/  matches abcd, abcbcd, abcbcbcd, ...</p>
<p>And you can multiply patterns with qualifiers {}<br />
/ab{3}c/ matches abbbc<br />
/a(bc){4}d/ matches abcbcbcbcd</p>
<p><span style="color: #0000ff;">CONTROL CLASSES</span></p>
<p>There are some control classes, or groups of characters represented by a word. They are set off with [: :]</p>
<p>[:lower:] matches lower case letters, a but not A<br />
[:upper:] matches upper case letters, A but not a<br />
[:alpha:] matches letters any case, a,A<br />
[:alnum:] matches alphanumeric, letters or numbers a,A,2<br />
[:space:] matches a space<br />
[:blank:] matches a space or tab<br />
[:digit:]{3} matches any three digits, 012, 213, ...</p>
<p>[:cntrl:] matches control characters.  Control characters are null, bell, backspace, horiz tab, line feed, form feed, carriage return, escape, and delete.</p>
<p>[:punct:] matches punctuation, such as ! " # $ % &amp; ' ( ) * + , - . / : ; &lt; = &gt; ? @ [ \ ] ^ _ ` { | } ~.</p>
<p>[:xdigit:] matches hexadecimal digits, 0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f</p>
<p>Regular expressions can be put together into some fairly complex patterns. They'll look so complicated, you'll wonder how it ever works.</p>
<p>Let's do one, a simple US zip code allowing both the 5 and 9 digit zips.  Here goes,</p>
<pre class="brush:php">/^([0-9]{5})(-[0-9]{4})?$/</pre>
<p>This reads at the start of the string match a digit exactly  5 times, group, and in the next group, match a -, match a digit exactly 4 times, and in the second group either 0 or one match only on the - 4 digits, and finally the string ends with none or - 4digits.</p>
<p><a title="Regular Expression Online Test Tool" href="http://www.solmetra.com/scripts/regex/index.php" target="_blank"><span style="color: #0000ff;">Onliine Test Tool</span></a></p>
<p>So you don't get lost in building your regular expression, there is an online regular expression test tool, <a title="Regular Expression Test Tool" href="http://www.solmetra.com/scripts/regex/index.php">here</a>, that I'd like to recommend.   This will give you the ability to insert a pattern, insert a test string, and see if your pattern works before you use it in your code.  The tester, along with a good basic knowledge of regular expression syntax, will go a long way toward making searching and validating your data a lot easier.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2013/03/10/regular-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Regular Expression Functions</title>
		<link>http://www.geekgumbo.com/2013/03/03/php-regular-expression-functions/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-regular-expression-functions</link>
		<comments>http://www.geekgumbo.com/2013/03/03/php-regular-expression-functions/#comments</comments>
		<pubDate>Sun, 03 Mar 2013 23:11:33 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=4948</guid>
		<description><![CDATA[When you use a regular expression, you create a special regular expression syntax pattern.  That pattern is then used to search the supplied text for that pattern, and then do something if it finds the pattern.  It can be used &#8230; <a class="more-link" href="http://www.geekgumbo.com/2013/03/03/php-regular-expression-functions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.geekgumbo.com/wp-content/uploads/2013/03/hipowl.gif"><img class="alignleft  wp-image-4967" alt="hipowl" src="http://www.geekgumbo.com/wp-content/uploads/2013/03/hipowl.gif" width="224" height="286" /></a>When you use a regular expression, you create a special regular expression syntax pattern.  That pattern is then used to search the supplied text for that pattern, and then do something if it finds the pattern.  It can be used to verify and find credit card numbers, zip codes, and words that start with "t" and end with "s," for example.</p>
<p>PHP has nine funcions that help with regular expressions.  I'm going to review each function quickly.  To make things easier, we can group the nine functions into three groups: functions used to test for a pattern, functions used to insert text, and functions used to output patterns found in the text.</p>
<p><strong><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">FUNCTIONS USED TO TEST</span></span></strong></p>
<p>These functions are meant to be used with "if" statements and yield true, if it is a match, or false, if there is not a match.</p>
<p><span style="color: #ff6600;">PREG_MATCH</span></p>
<p>Preg_match looks to see if there is a match between the regular expression and the string your testing, like so:</p>
<pre class="brush:php">$source = "The quick brown fox jumped over the lazy dog.";
$pattern = "/quick/";  // look for the word 'quick'

if (preg_match($pattern, $source))
{
    //do something
    jump();
}</pre>
<p>The output of preg_match is either 1 or 0.  There is either a match or not.  It stops searching after it finds a match. In the above example, the word "Quick" with a capital Q would not be a match, we'd have to have the pattern  "/quick/i" (the i for case-insensitive) to do that.  Preg_match is probably the most used of the preg functions.</p>
<p><span style="color: #ff6600;">PREG_LAST_ERROR</span></p>
<p>This function returns the error code from the last preg_ function you  ran.  Error code patterns are a set of PHP predefined constant error patterns.  It is often used with PREG_MATCH to see if an error has occurred while matching.</p>
<pre class="brush:php">preg_match($pattern, $source);

if(preg_last_error() === PREG_RECURSION_LIMIT_ERROR)
{
echo ("Recursion limit was exhausted!");
}
else if (preg_last_error() === PREG_BACKTRACK_LIMIT_ERROR)
{
echo ("Backtrack limit was exhausted!");
}</pre>
<p>There are 13 pre-defined regular expression error patterns in PHP. If you are checking for errors check the PHP manual for a list of these constants.</p>
<p><span style="text-decoration: underline;"><strong><span style="color: #0000ff; text-decoration: underline;">FUNCTIONS USED TO INSERT TEXT</span></strong></span></p>
<p><span style="color: #ff6600;">PREG_SPLIT</span></p>
<p>preg_split  splits a string into different array items.</p>
<pre class="brush:php">$pattern = "/ /";
$source = "123456789";
$result = array();

$limit = 4;  // optional - do 4 characters
$flag = "PREG_SPLIT_NO_EMPTY"; // optional - predefined PHP constants.  This one returns only non-empty characters

$result = preg_split($pattern, $source, $limit, $flag);

echo $result;

Which returns:  Array(0=&gt;1, 1=&gt;2, 2=&gt;3, 3=&gt;4, 4=&gt;56789)</pre>
<p>The reason all the numbers are not comma separated, is we used the $limit to only do four matches. The $flag variable is a set of three PHP predefined constants you can use in splitting strings.</p>
<p><span style="color: #ff6600;">PREG_QUOTE</span></p>
<p>Preg_quote is unique in that it places a \ in front of any reqular expression characters.  It is set up differently then other preg functions.</p>
<pre class="brush:php">$delimiter =  "#"; // optional - a replacement character other than "\"
$source = "The quick brown fox cost me $600 when it bit my dog.";

$result = preg_quote($source, $delimiter);
echo $result;

The result is: The quick brown fox cost me #$600 when it bit my dog#.</pre>
<p>Without the delimiter it would read: The quick brown fox cost me \$600 when it bit my dog\.  This is useful for escaping characters for printing.</p>
<p><span style="text-decoration: underline;"><strong><span style="color: #0000ff; text-decoration: underline;">FUNCTIONS USED TO OUTPUT</span></strong></span></p>
<p><span style="color: #ff6600;">PREG_REPLACE</span></p>
<p>preg_replace performs a regular expression search and replace.</p>
<pre class="brush:php">$source =       // What to search
$pattern =      // The search pattern
$replacement =  // What to use as a replacement
$limit =        // optional - The number of replacements to do
$count =        // optional - The number of replacements made
$result =       // The array that is returned

$result = preg_replace ($pattern, $replacement, $source, $limit, $count)</pre>
<p>A Limit of -1 will do all the replacements.  The entire $source is returned with the replacement strings in place.</p>
<p>This is an interesting function as you could have several patterns and replacements in an array.  There is a surprisingly good example on the PHP web site.</p>
<pre class="brush:php">$string = 'The quick brown fox jumped over the lazy dog.';
$patterns = array();
$patterns[0] = '/quick/';
$patterns[1] = '/brown/';
$patterns[2] = '/fox/';
$replacements = array();
$replacements[2] = 'bear';
$replacements[1] = 'black';
$replacements[0] = 'slow';

echo preg_replace($patterns, $replacements, $string);

The result is:

"The bear black slow jumped over the lazy dog."</pre>
<p>These functions usually output a $result variable that is an array of pattern matches that you use elsewhere in your code.</p>
<p><span style="color: #ff6600;">PREG_FILTER</span></p>
<p>This is identical to preg_replace, it does a search and replace based on a pattern, but it filters out what doesn't match, and returns the replace items in an array.</p>
<pre class="brush:php">$result = preg_filter( $pattern, $replacement, $string, $Limit, $count);</pre>
<p><span style="color: #ff6600;">PREG_REPLACE_CALLBACK</span></p>
<p>This is identical to preg_replace. It performs a regular expression search and replace, but instead of a $replacement value a callback is specified.</p>
<pre class="brush:php">$source = "The quick brown fox jumped over the lazy dog.";
$pattern = "/quick/";  // looking for the lowercase word "quick"
$limit = -1;
$matches = array();

function theCallBack($matches)
{
    echo $matches[0];
}

$preg_replace_callback($pattern, 'theCallBack', $source, $limit, $count)</pre>
<p>Every time the word "quick" matches the callback is fired.  In this case, the word quick will be in $matches[0].</p>
<p><span style="color: #ff6600;">PREG_MATCH_ALL</span></p>
<p>Preg_match_all matches repeatedly all occurrences of a pattern in an array or string and outputs the results to a multidimensional array.  It does not stop after the first occurrence, like preg_match.  This function is useful to pull out specific information from a document.  It can be used to pull out all javascript source files in a web page, for example.</p>
<pre class="brush:php">$source = file_get_contents("http://www.geekgumbo.com");  // Open a web page source
$pattern = " /src=[\"']?([^\"']?.*(js)[\"']?/i " ;   // Start with "src=" and end with a quote, or double quote, after the ".js"
$result = array();

preg_match_all($pattern, $source, $result);</pre>
<p>The result might looks something like this.</p>
<p>$result [0][0] -&gt; src="../../js/jquery.js"<br />
$result [0][1] -&gt; src="../../js/script.js"<br />
$result [1][0] -&gt; ../../js/jquery.js<br />
$result [1][1] -&gt; ../../js/script.js<br />
$result [2][0] -&gt; js<br />
$result [2][1] -&gt; js</p>
<p>If you want to play around with preg_match_all, a perfect way to see all the results easily is using my newchk utility at "<a title="Newchk web site" href="http://www.newchk.com">http://www.newchk.com</a>".</p>
<p><span style="color: #ff6600;">PREG_GREP</span></p>
<p>Preg_grep is like the grep command in Linux.  It searches through an array and returns all the matches of a particular pattern into a result array.  Let's look.</p>
<pre class="brush:php">$source = array("apples", "appricots", "oranges", "grapes", "bananas");
$pattern = "/^ap/";  //begins with an "ap"
$result = array();

$result = preg_grep($pattern, $source);

print_r($result);
// Prints: "Array ( [0] =&gt; apples [1] =&gt; appricots )"</pre>
<p>In the above example, preg_grep returned all fruits starting with the letters "ap".</p>
<p>There is an interesting option, where you can return an array of all the items that do not match the pattern by adding "preg_grep_invert," like so.</p>
<pre class="brush:php">$nomatch = array();
$nomatch = preg_grep($pattern, $array, preg_grep_invert);
print_r($nomatch);

// Prints "Array ( [2] =&gt; "oranges" [3] =&gt; "grapes" [4] =&gt; "bananas" )"</pre>
<p>Notice that the result array maintains the orginal array keys.</p>
<p>Preg_match is by far the most used regular expression function, followed by preg_replace.  This post did not intend to be a complete write-up on regular expression functions, but rather useful as a quick look-up when writing code as to the syntax and intent of a preg function.   Check the  PHP manual for the definitions of any constants referred to in the article and further explanation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2013/03/03/php-regular-expression-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web Development Tools</title>
		<link>http://www.geekgumbo.com/2013/02/17/web-development-tools/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=web-development-tools</link>
		<comments>http://www.geekgumbo.com/2013/02/17/web-development-tools/#comments</comments>
		<pubDate>Sun, 17 Feb 2013 04:19:03 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=4913</guid>
		<description><![CDATA[A web developer, over time, gathers a suite of tools to make his job easier.  I thought it might be interesting to my readers to go through the current tools I'm using and give you my 50,000 foot view of &#8230; <a class="more-link" href="http://www.geekgumbo.com/2013/02/17/web-development-tools/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.geekgumbo.com/wp-content/uploads/2013/02/wwwjpeg220.jpeg"><img class="alignleft size-full wp-image-4936" alt="wwwjpeg220" src="http://www.geekgumbo.com/wp-content/uploads/2013/02/wwwjpeg220.jpeg" width="220" height="143" /></a>A web developer, over time, gathers a suite of tools to make his job easier.  I thought it might be interesting to my readers to go through the current tools I'm using and give you my 50,000 foot view of what the tool is good for, and maybe why I find it better than other tools.</p>
<p>I run a Windows 7 Development environment at work doing open-source development.  I communicate with various Linux servers during the course of the day.  All the utility tools listed here run on Windows 7, are open-source, and thus free, for you to download and use.</p>
<p>Let's start with "<span style="color: #008000;">WampServer"</span> - I use WampServer as my Apache, PHP and MySQL localhost server.  I prefer WampServer, over XAMPP, because of the toolbar menu in the lower right corner is easy to use and has a lot of functionality, and its easy to set up virtual hosts in the menu.  See my article on  "<a title="Wampserver" href="http://www.geekgumbo.com/2012/10/29/mulitple-virtual-hosts-in-wampserver/">Multiple Virtual Hosts in WampServer</a>".    A word to the wise on this one.  Beware the 64bit version of WampServer, at this writing, it has bugs.  Go with the 32 bit Version.  It works great.</p>
<p>For an IDE, I use "<span style="color: #008000;">NetBeans"</span>.  I like NetBeans, over Eclipse, because it is a more streamlined and an easier user interface. See my article on "<a title="NetBeans Review" href="http://www.geekgumbo.com/?s=netbeans">NetBeans 7.1 Review</a>"</p>
<p>I use several different editors, besides NetBeans, depending on what I need to do.  On Linux, I use Vim.  I have Vim loaded in Windows, and use it when I go to the command line. The others don't count, including the elusive EMACS.  I should get some response on this one.  All in good fun :-}</p>
<p>My most used editor is <span style="color: #008000;">"Notepad++"</span>.  I highly recommend this editor, I'm usually back and forth in it all day.  I use it to write and save snippets of code, among other things. What's nice is it keeps all your current tabs open every time you open the editor until you specifically close the file.</p>
<p>My current project has a lot of compressed JavaScript, which is difficult to read.  To uncompress and edit the file, I use the "<span style="color: #008000;">Free JavaScript Editor</span>".</p>
<p>For version control, I use "<span style="color: #008000;">Git</span>".  There are now two environments for Git for Windows, Mysysgit and git-scm, each does the job.  I liked and used Mysysgit for years, and am now using git-scm.  It has a nice icon, but I'm finding a couple of quirks.  I will probably go back to Mysysgit next time.  It's a toss up.  This is one where you migrate back and forth.</p>
<p><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">What about Images:</span></span></p>
<p>For viewing images, I use "<span style="color: #008000;">XnView</span>".  It works great, and allows you to quickly access pictures on your PC.  For years, I used IrfanView and stayed with it, mostly because I liked their panda icon.  I know, dumb.  XnView has a better interface.</p>
<p>Picking Colors from any where on the screen: "<span style="color: #008000;">ColorCop</span>".  I use to use it to measure screen distances, but I've found that Windows 7 has messed up this feature.  Hopefully, it will be fixed in the future.  It's still the best color picker I've used.  I'm looking for a utility to measure screen distances in pixels.</p>
<p>For editing an image, I like "<span style="color: #008000;">Gimp 2.6</span>".  I found that 2.8 is not my "cup of tea" with the unified menu.  And I don't like that I have to export the image to save it in another format.  I got use to 2.6.</p>
<p>Taking a snapshot of the screen for this blog, for example, I use "<span style="color: #008000;">Greenshot</span>".</p>
<p>For reading PDF's or ebooks, I like "<span style="color: #008000;">MartView</span>".  See my article on "<a title="Martview" href="http://www.geekgumbo.com/2010/09/04/martview-pdf-reader-a-review/">MartView - PDF Reader</a>".</p>
<p><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">Behind the Scenes Utilities:</span></span></p>
<p>My hands down favorite is "<span style="color: #008000;">AutoHotKey</span>".  If you don't have this yet,  get it.  It will improve your productivity.  This little utility will allow you to bring up web sites, start applications, and enter strings of text to the screen with a couple of key strokes, of your choosing. 5 STARS.  See my article "<a title="AutoHotKey" href="http://www.geekgumbo.com/2011/06/06/autohotkey-for-windows-a-review/">AutoHotKey for Windows</a>".</p>
<p>As long as we're messing with keys, to remap your keyboard, try "<span style="color: #008000;">KeyTweak</span>", and turn off that annoying CapsLock key.  I wrote an article on KeyTweek <a title="Key Tweak" href="http://www.geekgumbo.com/2011/09/17/turning-off-the-caps-lock-key-in-windows-7/">here</a>.</p>
<p>For saving my clipboard contents, I use "<span style="color: #008000;">Spartan</span>".  It is very configurable, easy to bring up, and you can save past copies, like your favorite web sites in a permanet area.</p>
<p><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">Working with Files:</span></span></p>
<p>For finding lost files on my computer, I use "<span style="color: #008000;">Everything</span>".  I like the way it eliminates your possible choices as you type, and once it scans your files when I log in, it's lightning fast. See my article on <a title="Everything" href="http://www.geekgumbo.com/2010/04/05/search-everything-a-review/">Search Everything</a>.  By the way, Windows 7 Search does not find every file.</p>
<p>For searching for specific text strings inside of files, like in what files do I find the term "&lt;a title="Milestone" in a group of files, and at what line number.  On Linux it's grep, on Windows, I use "<span style="color: #008000;">AstroGrep</span>," and it too is fast.</p>
<p>For finding the difference in two or three versions of the same file.  I like "<span style="color: #008000;">P4Merge</span>".  It also integrate well with Git.  See my article on: "<a title="P4 Merge" href="http://www.geekgumbo.com/2010/05/11/perforces-p4merge-file-comparison-editor-a-review/">P4Merge File Comparison Editor</a>"    I've heard good things about "Beyond Compare," but that's not free.</p>
<p>For extracting compressed zip and tar files, I prefer: "<span style="color: #008000;">7Zip</span>".</p>
<p><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">SQL Tools:</span></span></p>
<p>Of course, a nod to "<span style="color: #008000;">phpMyAdmin</span>" which comes with WampServer, a good tool.</p>
<p>For writing queries, I like the older "<span style="color: #008000;">MySQL Query Browser</span>" over any of the later tools.  Better hurry if you want this tool as Oracle is moving to retire it.</p>
<p>A tool I don't care for, that other developers seem to love, Toad.  It's got bugs, it's not fail safe, and has a crappy database export.</p>
<p><span style="text-decoration: underline;"><span style="color: #0000ff; text-decoration: underline;">Windows Utilities:</span></span></p>
<p>I have to give a nod to Scotty and "<span style="color: #008000;">WinPatrol</span>"  No one can mess with my Start Up files without my knowing about it.</p>
<p>Clean up the trash - "<span style="color: #008000;">CCleaner</span>" can't be beat, although I wish they didn't come out with so many new versions.</p>
<p>I use both "<span style="color: #008000;">Malwarebytes</span>" and "<span style="color: #008000;">Spybot Search and Destroy</span>" for cleaning out malware.  Malwarebytes takes longer to run, but does a better job.  Both clean up different types of malware.  It's a toss between "<span style="color: #008000;">AVG</span>" and "<span style="color: #008000;">Avast</span>" on antivirus, I've used both.  And my firewall, which has now gone to its grave is "<span style="color: #008000;">PC Tools Firewall Plus</span>".</p>
<p>For killing processes, which the Task Manager can't seem to do, if your running XP, check out "<span style="color: #008000;">SysTree++</span>".  It's awesome.  Any other Windows, I recommend "<span style="color: #008000;">Microsoft Process Explorer</span>", its free.</p>
<p>I know I've missed a couple here and there, but these are the tools I use every day.  I'm all ears to any other suggestions you might have for tools you use and love.</p>
<p>The two tools I use and love the most is Notepad++  and AutoHotKey.  So there you have it, what my work environment looks like.  I hope it has given you some new ideas for software to try out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2013/02/17/web-development-tools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Working with Files</title>
		<link>http://www.geekgumbo.com/2013/02/10/php-working-with-files/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-working-with-files</link>
		<comments>http://www.geekgumbo.com/2013/02/10/php-working-with-files/#comments</comments>
		<pubDate>Sun, 10 Feb 2013 15:37:44 +0000</pubDate>
		<dc:creator>daleV</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.geekgumbo.com/?p=4883</guid>
		<description><![CDATA[Although I don't get much chance to write to files directly, since most of my work is with databases, every once in awhile its nice to know how to do this. Working with files is much like working with a &#8230; <a class="more-link" href="http://www.geekgumbo.com/2013/02/10/php-working-with-files/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Although I don't get much chance to write to files directly, since most of my work is with databases, every once in awhile its nice to know how to do this.</p>
<p>Working with files is much like working with a database, you first have to open a connection to the file, then, like with a database, you can: create a new file, read the file, and update the file. After you're done with the file operation, you close the file, just like you close a database. Let's see how we do this with PHP.</p>
<p>First, to open a file we use the fopen command like so:</p>
<pre class="brush:php">$fileName = "testFile.txt";
$fileHandle = fopen($fileName,'a') or die("can't open file");</pre>
<p>The fopen command generates a link to the file called, a file handle. We use the file handle for the rest of our file operations as a pointer to the file.</p>
<p>When you open a file, it is expected, that the programmer will know what he wants to do with the file. The fopen commands asks why the file is being openned. There are several choices to substitute for the 'a' in the fopen command:</p>
<p>'<span style="color: #008000;">r</span>'  Open for reading only; File pointer at the start of the file.</p>
<p>'<span style="color: #0000ff;"><span style="color: #008000;">r+</span>'</span> Open for reading and writing; File pointer at the start of the file.</p>
<p>'<span style="color: #008000;">w</span>'  Open for writing only; File pointer at the start of the file; Delete any contents. If the file does not exist, create it.</p>
<p>'<span style="color: #008000;">w+</span>'  Open for reading and writing; File pointer at the start of the file, Delete any contents. If the file does not exist, create it.</p>
<p>'<span style="color: #0000ff;"><span style="color: #008000;">a</span>'  </span> Open for writing only; File pointer at the end of the file. If the file does not exist, create it.</p>
<p>'<span style="color: #008000;">a+</span>'  Open for reading and writing; File pointer at the end of the file. If the file does not exist, create it.</p>
<p>'<span style="color: #008000;">x</span>'  Create and open for writing only; File pointer at the start of the file. If the file exists, generate an E_WARNING.</p>
<p>'<span style="color: #008000;">x+'</span>  Create and open for reading and writing; File pointer at the start of the file. If the file exists, generate an E_WARNING.</p>
<p>Quite an array of options. There are a few more, but these are the main choices. In reality, if you're adding to the contents of the file, like with a log or error file, you want to add the contents below anything else in the file, so the "a" is appropriate. If you're creating a new file, you would probably want to use the "w" or "x" to avoid overwriting an existing file. If you're just reading the file, a simple "r" will do.</p>
<p>Now that we have the file open, how do we add content and read the file.</p>
<pre class="brush:php">$fileName = "testFile.txt";
$fileHandle = fopen($fileName, 'a') or die("can't open file");

$strTest = "The string to write to the file.";

// To write to the file
fwrite($fileHandle, $strTest);

// Close the file after the write
fclose($fileHandle);</pre>
<p>The fwrite command says write the $strTest to the file. Since we openned the file to append, "a", $srtTest will be added to the end of any contents in the file.</p>
<p>How about reading, we could use fread() , like so:</p>
<pre class="brush:php">$fileName = "testFile.txt";
$fileHandle = fopen($fileName, 'a') or die("can't open file");

// If we want to read the entire file
$lengthOfRead =  filesize($filename);

// You assign the output of the fread to a variable
$result = fread($fileHandle, $lengthOfRead);

// If we want to read a line at a time
while (!feof($fileHandle))
{
	echo fgets($filehandle);
	// carriage return for a new line
  	echo "\t";
}

fclose($filehandle);</pre>
<p>The $lengthOfRead variable is the amount of the file you want to read, in bytes. feof() tests for the end of the file. fgets() reads a line at a time.</p>
<p>Carriage returns at the end of the line are different for different operating systems. Use "\r" for the Mac, and "\n" for Linux, and Windows needs a "\r\n". In Windows, if you use a "\t" it will pick the right line ending for you.</p>
<p>There are few other commands in PHP that combine the fopen, fread or fwrite, and fclose all in one command, that I recommend.</p>
<pre class="brush:php">file_puts_contents("testFile.txt", $strTest )

$fileContents = file_get_contents("testFile.txt");</pre>
<p>file_puts_contents is identical to calling fopen(), fwrite() and fclose() successively to write data to a file. If the file exists the content will be overwritten. If the file doesn't exist it will be created.</p>
<p>file_gets_contents reads the entire file as a string to memory.</p>
<p>ANd there is one more way to read a file:</p>
<pre class="brush:php">$fileContents = readfile("testFile.txt");</pre>
<p>The main difference is that readfile writes its contents to the output buffer instead of memory. You can output it directly to your screen with a</p>
<pre class="brush:php">print($fileContents).</pre>
<p>As you can see, there's more than one way to accomplish the same task in PHP. You just need to know what you're trying to do, before you start doing it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekgumbo.com/2013/02/10/php-working-with-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
