PHP

SAAS Problem of the Week Quiz Decoder

Script that figures out the answers to SAAS POTW Quiz’s. As a note, this is only the processing end. In order for the script to work, you will need to build a front end.

<?
error_reporting  (E_ERROR | E_WARNING | E_PARSE);
$httpfile = $_POST['httpfile'];
$userfile = $_POST['userfile'];
if($httpfile != NULL){
$textarea = file_get_contents($httpfile);
}
else{
$textarea = file_get_contents($_FILES['userfile']['tmp_name']);
} 
    echo "1. ";
    $t = 2;
    $length = strlen($textarea);
    for($i = 0; $i < $length; $i++){
        if(($textarea[$i-1].$textarea[$i]) == "l["){
            while($textarea[$i+1].$textarea[$i+2] != ",#"){
                $i++;
                echo $textarea[$i];
            } 
            $i++;
            if($t > 10){
            die();
            }
            echo "$t. ";
            $t++;
        } 
    } 
?>

Note: This was code that I originally had in a ‘Code’ page, but I’m moving it to a post now. This code is probably really old (years and years old). I enjoy laughing at myself and so should you.

0

Handling Links

This is some code that I cooked up for handling links in my website. I was tired of prefacing every link with “”. This takes care of that and ensures that it will open in a new window. Easy as pie. I’m sure there is probably a better way to do it, but this is the way I figured out how to do it.

function redirect ($url)
{
$url = preg_replace(“#Note: This was code that I originally had in a ‘Code’ page, but I’m moving it to a post now. This code is probably really old (years and years old). I enjoy laughing at myself and so should you.

0

Making HTML XHTML Compliant with PHP

This is function I found on php.net that changes all HTML tags to lower case. You need this to make your HTML XHTML 1.0 Trans compliant.

function reformat ($content){
	$content = preg_replace("#(<\/?)(\w+)(&#91;^>]*>)#e", "''\1'.strtolower('\2').'\3'", $content);

	return $content;
}

Note: This was code that I originally had in a ‘Code’ page, but I’m moving it to a post now. This code is probably really old (years and years old). I enjoy laughing at myself and so should you.

0

Countdown Timer v2.0, Now with v2.01 goodness!

Update: There was a bug in the initial 2.0 version that required the plugin to have PHP5 or greater. This has now been fixed and it works with PHP4 and PHP5. Thanks to Jim Lynch for bug report.

Well, I finally managed to push Countdown Timer v2.0 out the door. It’s a bit later then I wanted, but it’s out and that’s all that matters for now. The biggest update for v2.0 is the ability to have the time automatically update using some Javascript. The idea for this has actually been around for a while and credit for it goes to Tobias (see: Ultimate Countdown Timer; 1-Up’d by a 14 Year Old). I was hoping I could use a lot of Tobias’ code, however I had changed a lot between then and now.

During the development phase, I wrote some code that basically took a look at what value the timer was at and then subtracted one second from that. Unfortunately, it quickly became clear that this method would not work. Because there are a variety of options in what units of time are displayed, screen scraping and then recalculating would have been pretty cumbersome. It also meant that I had two ways of calculating the time (the first way was the PHP-based fuzzyDate function I wrote, the second would have been this monstrosity). So I did what any code programmer does and copied myself. I converted the PHP-based fuzzyDate function into Javascript and then passed the needed values to the JS function. Voila!

In any event, here’s the changelog:

  • Updated plugin description line
  • Rearranged text in the installation notes to emphasize using the widget rather then the code
  • Fixed a bug that crashed the plugin if no dates were present (a PHP 5 problem??)
  • Implemented the ‘register_activation_hook’ function rather then the old way
  • Changed the way DB updates are handeled. Instead of having a specific update regimine for each version, the plugin will only update an option field if it doesn’t exist (if it exists, but is blank, it will NOT update…as it shouldn’t).
  • Updated fergcorp_countdownTimer_fuzzyDate with another variable so that the real target date is always known.
  • Removed code dealing with updates since WP 2.3 now does this automatically
  • Bug fix. Widget title isn’t saveable due to a programming error. Thanks to Michael Small for the catch.
  • Renamed some functions from afdn to fergcorp
  • Added JavaScript function for JS countdown
  • Tabbed $afdnOptions array to make it more readable
  • Fixed strtotime typo
  • Brought time display inline with current WordPress practice. This fixes the dreaded timezone glitch.
  • Strip non-sig zeros option added
  • Fixed bug where “No dates present” would _not_ show if the data was returned instead of echo’d
  • Renamed to $getOptions to $fergcorp_countdownTimer_getOptions to avoid clashing

Read more or download version 2.01!

Note: Comments moved and closed. Please leave future comments, questions, pleads for help, etc on the Countdown Timer page.

0

Countdown Timer v1.97 Technical Preview 2

It’s been many moons since I released the last technical preview of Countdown Timer 2.0. Honestly, things were stalled for a bit because I was busy with school and trying to figure out how I wanted to do what I wanted to do with the program.

The semester is over and I got it all figured out. So welcome to Countdown Timer version 1.97, better known as version 2.0 technical preview 2.

The Javascript that handles the updating of the countdown has been completely rewritten. I ended up scrapping what I had and then taking the PHP code I was already using and converted it to Javascript. This is the “elegant solution” I mentioned I was looking for earlier.

In terms of stability, everything seems fine; I am currently using this Technical Preview on AFdN. There are a couple known bugs that deal with stripping non significant digits and I haven’t fully tested the upgrade process. Other then that, everything is complete. I’m hoping to have 2.0 shipped before the New Year.

Go download it!

0

Google Chart API

I typically don’t blog about new Google stuff, especially APIs (application programming interfaces). However, this one is particularly cool because it allowed me to easily finish up a project that I had shelved for several months (maybe years? I’ll just call it ‘a while back’).

A while back, I had this idea to chart monthly blog frequency. I had found some code that did a pretty bang up job of making graphs using just PHP. However, it wasn’t the sleek looking graph I was hoping for. I had bookmarked a few sites that had Macromedia Flash applications that you could just drop the data into, but I never got around to playing with them.

Finally, Google introduced the Google Chart API. In a nut shell, I can easily create graphs such as:

Blog posts for Nov. 2007

This chart shows my blogging frequency for the month of November. The code I’m using on the back end is pretty crappy (I literally just patched some code I already had) and it can only handle a single month at a time.

Technical details to follow…
Read More »Google Chart API

0

Countdown Timer v1.91

Technically, this is a step back because I already released 1.95 as a Technical Preview. However, I wanted to fix a bug without having to release the incomplete features included in the 1.95 Technical Release. So this is a special release. This release fixes a bug where the widget wouldn’t save data. Baring any catastrophic bug discovery, this will be the last release before version 2.0 (which I hope to release over Christmas Break).

Read more or download it!

0

Countdown Timer v1.95 Technical Preview

Okay folks, this is a technical preview of version 2.0 of the Countdown Timer.

The biggest change is that timers can now countdown automagically with JavaScript. Now, a word on the JS. This is the first version and there are only two modes: on and off. That means that you can’t change the format of the Javascript countdown (it will always display the years, months, days, hours, minutes, and seconds). I’m working on an elegant solution to this problem and would welcome any code, comments, suggestions, feedback, etc.

Other updates include:

  • Tabbed $afdnOptions array to make it more readable
  • Fixed strtotime typo
  • Brought time display inline with current WordPress practice. This fixes the dreaded timezone glitch.
  • Strip non-sig zeros option added
  • Fixed bug where “No dates present” would _not_ show if the data was returned instead of echo’d

In terms of stability, everything seems fine; I am currently using this Technical Preview on AFdN.

Download the file and try the goodness

0