Archive for the 'Programming' Category

Storing Compressed Data in a MySQL Database

Saturday, January 7th, 2006


PHP Lesson

Sunday, May 1st, 2005

I feel so proud. My first post that isn’t a rant. Now, those who deem my blog worthy of their limited surf time will get a brief lesson in PHP that should minimize your code a bit.

Now, normally we use something like this for ifs:

if ($variable == 'Hello') {

right? Now what if we have lots of variables?

if ($variable == 'Hello' && $variable2 == 'Hello' && $variable3 == 'Hello' && $variable4 == 'Hello' && $variable5 == 'Hello') {

There is an easier way, and it minimizes if sizes.

$variable1 = 'Hello'; // These would be set already
$variable2 = 'Hello';
$variable3 = 'Hello';
$variable4 = 'Hello';
$variable5 = 'Hello';

$varray = array($variable1,
$variable2,
$variable3,
$variable4,
$variable5);

$val = array_fill(0, 5, 'Hello');
if ($varray == $val) {
echo 'Equal';
}

Tada, easy.

As suggested by a commenter, I am also including an example where this technique could be useful in practice.


$varray = array($_POST[’user’],
$_POST[’pass’],
$_POST[’verpass’],
$_POST[’email’],
$_POST[’name’]);

$val = array_fill(0, 5, NULL);
if ($varray != $val) {
// Execute code for form processing
} else {
// Display error
}

This would check if any of the form elements were empty, saving the need for large if conditional statements.

Note: this is outdated. Better methods are easy to come by, just check the comments below.


PHP

Thursday, April 21st, 2005

Many people on the CodingForums.com programming forum help people. These are the people like me, who give their time daily to help n00bs on their programming projects, and sometimes even code entire samples for them. Unless the person is genuinely stumped, and has attempted to fix their problem/create, or simply to better their knowledge they are n00bs in my eyes.

II. Defining ‘Noob’

Contrary to the belief of many, a noob/n00b and a newbie/newb are not the same thing. Newbs are those who are new to some task* and are very beginner at it, possibly a little overconfident about it, but they are willing to learn and fix their errors to move out of that stage. Noobs, on the other hand, know little and have no will to learn any more. They expect people to do the work for them and then expect to get praised about it, and make up a unique species of their own. It is the latter we will study in this guide so that the reader is prepared to encounter them in the wild if needed.

Besides the reasons above, they ask some of the most moronic questions I have seen to date. To illustrate this fact, I have posted a cartoon.

PHP Heal
Credit: joe-ks.com for original cartoon.