Dec 23 2007

New version (v2.0) of calendar.class.php now available!

A new version of my php calendar class is now available for download. This new version adds localization and the ability to mark dates that have passed. The download also now includes an examples directory with 8 demonstrations of using the class in various ways. A basic CSS file is also included with the examples as well.

Read the rest of this entry »

Oct 17 2007

Convert 24 hour (military) time to 12 hour (am/pm) time in php

The need to convert time from 24 hour format to 12 hour format is a pretty common task in php applications involving a database. MySQL (and most databases for that matter) require time in 24 hour format while humans prefer to read their time in 12 hour format. I recently ran across a blog post demonstrating numerous custom functions to do the trick, all of which are overly complex. A quick google search confirmed that this is another one of those common programming problems that many PHP programmers have been over engineering a solution for when PHP’s core functions provide a simple and elegant solution. In other words, there’s a much better solution…

Read the rest of this entry »

Oct 3 2007

Temporarily enable PHP error display with an htaccess file

PHP’s error reporting can be extremely helpful for debugging scripts while developing a new application. The problem with letting PHP display those error messages is it has the serious potential to reveal sensitive information about your server environment. For that reason, PHP’s error display generally is (and SHOULD BE) disabled for production sites. However, that can make finding and fixing problems in live code much more difficult.

One solution is to temporarily turn on error display with an htaccess file. Placing a php_flag command in an htaccess file allows for overriding the global settings present in PHP’s INI with a local value. Simply create a plain text file, paste the line of code below into the text file, then name the text file “.htaccess”

php_flag display_errors on

Upload your new htaccess file to the directory containing your broken PHP script and it will turn on PHP’s error reporting. Once you have the error message (hopefully including a line number where the error is occurring), just quickly remove the htaccess file and you’re back to normal with error reporting off.

You can override many of the php.ini directives with an htaccess file. Check out the PHP documentation on changing configuration settings for more information.

Sep 21 2007

Generating a ‘year-at-a-time’ calendar with calendar.class.php

In the previous post announcing the release of calendar.class.php I gave a quick example of how the class could be used to easily output multiple months. That example showed an interface made up of the previous, current and next month. Generating a full year at a time is just as easy to accomplish using a simple for loop. Here’s how…

Read the rest of this entry »

Sep 18 2007

calendar.class.php v1 released

As work progresses on the firepaper project, I found myself in need of a solid PHP class to generate calendar interfaces for things like picking dates for reviewing logged time, scheduling tasks, etc. I looked around for a while at how others were dealing with creating calendar displays and wasn’t satisfied with what I found.

A lot of the examples I found used mathematic calculations to get the days to line up on the proper day of the week and fall into the correct weeks (rows of the table). This seems unnecessary considering PHP’s date function provides everything needed to do the job. In addition I wanted the output to be semantically meaningful, easily styled and of course valid XHTML 1.0 Strict. So, I created my own calendar creation class, calendar.class.php, and I’m releasing it into the wild under a Creative Commons Attribution-Share Alike 3.0 License.

Read the rest of this entry »