Category Archives: Programming

Snood jerky on Windows 7

As every serious programmer knows, Snood is a must application for those moments when it is more important to think than to type. Why, Snood has been helping me program since 2003! So I was quite alarmed when I installed the latest version of Snood (4.x) on my newly built computer with Windows 7 and it was jerky. It is just not possible to play Snood when it’s jerky. You can’t aim straight and end up missing all kinds of clear shots.

I did some googling, as I do when ever I have an issue, and lo and behold, I found a solution! Revert back to Snood version 3.52. Perfect! I downloaded the older version directly from the Snood website (the one from CNet was actually the newer version, even though it is labeled as the older), and now I can play Snood productively!

lessons of the month

This month has flown right by, but not without some learning experiences. Here are some things I learned:

  • Never give Schr?die flea medicine while wearing a decent shirt; she still has back claws.
  • There is a limit as to how much milk one can ingest in the span of three minutes.
  • High school kids that play in pit bands are really cool.
  • The Comfort Inn is not that comfortable.
  • It can take 50 minutes to drive 5 miles when there is night construction on I-95.
  • Always make a backup of a database table before you do anything to it.
  • Agatha Christie is still a good read.
  • Some vampire cable shows should never have been made.

build readable strings recursively out of a form array in PHP

Here’s a great way to turn an array into readable strings in PHP. For example, I want an error notice to be sent to me automatically when a database action in a function fails. The problem is, I cannot possibly know what is going to be in every form that is used in the function that generates the database query. While I *can* easily get the keys and values using

foreach ($in_array as $key => $value)

and building a string, what if the value itself is an array? The value for any array within the array would be “Array”. Not very useful!

Fortunately, PHP functions can be recursive. Here’s a function I wrote to handle that:

function getArrayAsString($in_array)
{

$string = '<br />';
foreach ($in_array as $key => $value)
{

if (is_array($value)) $string = $string.'<br /><strong>'.$key.'</strong>: '.getArrayAsString($value).'<br />';
else $string = $string.'<strong>'.$key.'</strong>: '.$value.'<br />';

}
return $string;

}

Each value is checked to see if it is an array. If it is, it (the array value) is sent to this function, and it processes until all of its values have been evaluated, sending any of those array values into this function as well.

I use this function by concatenating the result to an error message by calling the function with the $_POST variable as the array parameter. This way, I have my custom-built message specific to the failed function, and I get all the information that was posted so I can evaluate the error without having to generate the array values one at a time, or worrying if any values are themselves arrays. Click here to fill out a form and see how this recursive function works.

Personally, I like my “keys” to be bold and the values to be normal, but you can change that to suit your tastes.