Jan 16 2008

Easy PHP GeoCoding with Yahoo Maps API

I just recently began a project for a client that will require a proximity search feature. Basically the visitor inputs their location, either city/state combo or zip code along with a proximity value (within 10 miles, 25 miles, 50 miles etc) and the search returns a list of businesses (in this case distributors of the clients product line) within that area. I’ve seen these types of searches many times, but this is the first time I’ve had occasion to build one.

To even begin a project like this you would generally need to get your hands on some kind of database mapping city/states and zip codes to latitude and longitude values before you could even start wondering how to calculate a radial distance area from those locations. Traditionally when it comes to these databases, you can either buy the data which is usually a little pricey and may carry a monthly subscription fee as well. Or you can dig around various federal government websites looking for the data only to find it 5 or 6 years out of date and compiled in way that isn’t quite what you wanted. Frankly, either option kinda sucks. Thankfully we now have very sophisticated mapping services from Google, Yahoo and Mapquest that can be leveraged for the task of geocoding locations.

Read the rest of this entry »

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 (or more precisely, a subset of humans known as “Americans” that are also prone to, on occasion, take for granted that their cultural habits are common to all humans… as pointed out by John in the comments below) 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 »