Check for a valid date in PHP, redux

This is an updated PHP based date validator, correcting some issues with the original version. An additional parameter has been added specifying the expected format of the date, using PHP date expressions.

function bi_IsDate($d, $f='%d-%m-%Y %H:%M'){
	if (empty($d))  return true;

	#Convert Unix timestamp to a std format (must not include regular expressions)
	if (preg_match('!\d{5,}!',$d))
		$d=strftime($f,$d);

	$re_day='%d|%e';
	$re_month='%m';
	$re_year='%g|%G|%y|%Y';
	$re_sep='[\/\-\.]';
	$re = array(
		'/'.$re_day.'/' => '(0?[1-9]|[12][0-9]|3[01])',
		'/'.$re_month.'/' => '(0?[1-9]|1[012])',
		'/'.$re_year.'/' => '(19\d\d|20\d\d)',
		'/%H|%I|%l/' => '([0-1]?\d|2[0-3])',
		'/%M/' => '([0-5]\d)'
	);

	$re_date = preg_replace(
		array_keys($re), 
		array_values($re), 
		$f);  #convert $f into a regular expression

	#does %d match the regular expression version of $f?
	if (preg_match('!^'.$re_date.'$!',$d,$x)  
		#determine expected date order based on $f and checkdate
		&& ((preg_match(
				'!^('.$re_day.')' .$re_sep .'('.$re_month.')' .$re_sep .'('.$re_year.')!',$f) 
				&& checkdate($x[2], $x[1], $x[3]))
			|| (preg_match(
				'!^('.$re_month.')' .$re_sep .'('.$re_day.')' .$re_sep .'('.$re_year.')!',$f) 
				&& checkdate($x[1], $x[2], $x[3]))
			|| (preg_match(
				'!^('.$re_year.')' .$re_sep .'('.$re_month.')' .$re_sep. '('.$re_day.')!',$f) 
				&& checkdate($x[3], $x[1], $x[2]))
	))  return true;
	return false;
}

BlogIt Release 1.3.0

The main new user feature in this release is the new UI for comment editing. The UI basically re-uses the exiting comment entry form, but exposes fields that would normally be hidden to the average user; as such it required very few lines of code. This is a good thing. As a general goal I'm trying to keep the size of BlogIt small, primarily to keep the entry barrier low for new contributors, and partly to keep maintenance overheads low.

Most other changes were developer oriented, aimed at grouping similar variables together into arrays, which hopefully makes things a little easier to read. One change I did make was to update the date validation routine. This has been flaky for a while, and I finally broke down and took a different approach to the validation. This version should allow for a little more variation in the date formats, as well as handling international formats a little better.

Next release will be a little more user oriented, and should see some Ajax goodness.

BlogIt RSS Feeds

Adding an RSS feed to my blogs has been on my todo list for a while now, but I just haven't made the time. Thankfully others have had the time, and managed to provide some good guidance on how how to set up an RSS feed for BlogIt, and in using BlogIt in general. Before the next BlogIt? release I'll give this a go. Thanks Trevor.

BlogIt Maintenance Release 1.2.2

Maintenance release 1.2.2 of BlogIt many of the day to day bugs found over the past 8 weeks or so since the last release. None of the bugs are critical, but it's worth upgrading, particularly if you tend to use apostrophes in your titles.

In addition to the help from prior contributor SteP who provided some code fixes, we also saw some additional participation from Peter Kay who as a first time BlogIt user managed to find some pretty interesting bugs, including the apostrophe issue, and a problem where non-BlogIt links in the sidebar were incorrectly rendered with hyphens. Thanks Peter.

Hopefully as BlogIt matures we'll start to see increasingly broader involvement from the PmWiki community. One day we might even get us a code review.

Enlighten: PmWiki Skin Conversion

Enlighten is my latest contribution to the PmWiki platform. Nothing too special here: a basic 2-column blog layout. But it was easy to produce, and helped me narrow the time it takes to do each part of a skin conversion. Turns out the basic conversion is pretty quick. A few hours. What adds the time is all the extras. Adding fixed/fluid width support; multi-color themes; support for BlogIt. All told, it seems to take around 20 hours to do a skin conversion.

Blogging with PmWiki: BlogIt

BlogIt provides a pretty comprehensive blogging platform for PmWiki. The Blogit project page is maintained separately, but the BlogIt tag on this site will provide basic updates, and my current thinking on what's coming up next. I run all my blogs using BlogIt -- you can check them out from the main tab links at the top.

You can also check out the open demo -- the Admin password is "blogadmin", and the Edit password is "blogedit" -- no user name is needed. Feel free to add new blog entries, add comments, login as admin and approve a few comments.

I've used most of the more popular blogging platforms in the past few years, but most of them fell short many areas, but in particular in their ability to provide blogs across multiple domains, running from a single installation of the software. I wanted to maintain a few blogs on very different topics, hence the domain separation, but did not want to have the hassle of maintaining multiple software installations, with numerous skins, extensions, and upgrades that managing a self-hosted blog entails. Not one of the many platforms available was able to do this effectively. There were a few that came close (Lyceum, and Drupal were closest), but each came with their own additional baggage, which in both cases ended up in abandonment.

Read more...

Set IFRAME height based on size of remotely loaded content

When you load a remote page (a page which is not on your domain) into an IFRAME how do you ensure that the IFRAME expands its height to completely wrap its content, and has no vertical scroll bars (avoids having both the browser scroll bar and an iframe scroll bar), regardless of the content loaded? Well unless you have the willing consent of both domain on which the remote content is stored, you don't. But, if you can all agree to get along, then it is possible to seamlessly load remote content into your page, with no scrollbars, borders, or other visual queues of content being stored elsewhere.

The technique for cross-domain communication is used by Facebook, iGoogle, and Google Maplets, but there doesn't seem to be wide recognition of when and how it can be used.

Works across browsers, including Chrome, Firefox, Opera, Safari, and even Internet Explorer 6/7/8.

Read more...

Google Wave

Google Wave is being developed under the leadership of the same brother team that developed Google Maps (Lars Rasmussen and Jens Rasmussen), and basically re-envisions the 35+ year old email concept, from todays perspective -- really a personal social dashboard. 2 years in development using Google Web Toolkit, Google Wave mashes together and federates a huge number of more recent social and collaborative concepts, from email, IM, file and image sharing, document collaboration, wikis, blogging, and more. Say bye to having to manage 35 different social networks! Wave will consolidate them all into a single interface. Along with every other collaboration and social tool you use. Oh, and it's also a protocol -- more on that later.

And it does this in real-time, within a browser. Read more...

How to install AdSweep for Google Chrome

Update 16-Nov-2009: Looks like Chrome 4 is not yet supported by AdSweep. In addition it looks like AdSweep was abandoned by the original author, and has been taken over by someone else, and the AdSweep site itself has been turned over to low-life advertising. At this point, I'd recommend not using AdSweep. I have not yet found any good alternatives -- let me know if you find anything.


There have been numerous ways to block ads in Google Chrome for a while now. The more popular is Privoxy which has the side effect of being a pain to get running, and affecting all web traffic on your machine. Well, there is finally an 'easy-to-install' way of ad-blocking in Chrome.

Be aware that this version of AdSweep is itself early in development, so there is no UI, nor any auto-update mechanism.

At the moment you need to be running the 2.0 development version of Chrome. Full instructions are here, but in summary:
Read more...

Check for a valid date in PHP

Update 30-Jan-2010: This version doesn't work if the date format switches the day and month. Check out the updated version for a fully functional date validator.

PHP is an atounding language. There are 48 different functions to do things with dates and times. And the one to validate that a given string is a valid date requires you to do your own date parsing.

Here's a simple routine that takes a dd-mm-yyy H:M date string (optionally including a timestamp), or a Unix timestamp, and checks to see that it's a valid date. Read more...