Aug 15

For whatever reason, the ternary operator is not used very often in PHP. Hell, I didn't even know what it was until several months ago. However, it is a very useful tool. Basically, it's a short way of condensing if statements with only one result. Example:

if($_GET['variable'] == "yes"){
	$flag = true;
}
else{
	$flag = false;
}

That's 6 lines of code for something that is VERY simple. Let's look at the ternary operator version:

$flag = $_GET['variable'] == "yes" ? true : false;

One line! Much better. Let me explain how this works. When using the ternary operator, you have 3 statements, arranged like so:

[statement 1] ? [statement 2] : [statement 3]

They evaluate like this: if [statement 1] evaluates true, then [statement 2], or else [statement 3]. So, in our example, if you set the $_GET['variable'] to "yes", $flag would equal true, otherwise it is set to false. However, it's not just limited to one statement. For example:

$flag = $_GET['variable'] == "yes" ? ($_GET['variable2'] != "no" ? true : false) : false;

If $_GET['variable'] is yes, and $_GET['variable2'] isn't no, then flag is true, otherwise it is false. That would've taken a lot more code without the ternary operator, wouldn't it? Yet we managed to do it in an entire one line.

Aug 11
  • Number 1: HijackThis
    hijackthis
    Description: Hijackthis is an excellent spyware scanner and remover. It is, in my opinion, the best free spyware software available. It also has other useful functions such as deleting files on startup, disabling startup processes, and viewing DLLs in use by running processes.
    Link: MajorGeeks.com
  • Read the rest of this entry »

Aug 10

If you're like me, you hate opening Command Prompt from Run, then change directories manually to wherever you're trying to access. Open Command Here is a plugin for Explorer to let you open a Command Prompt window to the folder you have selected. I use this more than anything else on my computer, and I definitely recommend it.

Aug 10

Sorry I haven't updated in a couple days, but I've been very busy. Today I want to show you an image captcha script I have been working on. You can see a demo here and the sourcecode here. Let me know what you think of it! :)

Just in case you're wondering about the GET variable "r", I only added it for the JavaScript refresh script. You can do whatever you want to tell the script to generate a new image.

I also haven't gotten any submissions for the PHP contest! I was really hoping this would be a popular contest, but so far no one has made the effort :(

Aug 2

Here's the challenge: You must write the most complex function that you can simply to return the number 13337. The winner will be the person who submits the most complex and/or humorous function to complete this task.

Rules:

  • Must be in PHP. Sorry, I don't want to waste time trying to figure out your Java function
  • Comments do not add to to overall length
  • Must not contain any exec() or similar functions
  • Submissions must be received by September 1, 2007

The winner and 2 runners-up will have their function posted here.. I don't really have any prizes to give because I'm broke, but isn't the everlasting fame worth it? Get cracking!

All submissions should be sent to _@_._ by the deadline.

« Previous Entries Next Entries »