Dented Reality

Monthly Archives: July 2009

Quick PHP Tip

If you’re coding in PHP and checking variables to see if they have a strlen() == 0, or isset() or a variety of other possibilities, you might consider using empty() instead. It’s quite versatile and is nice because it doesn’t trigger any warnings or notices if you use it on a variable which hasn’t been set yet. Here are some examples to show you what it will match against:

<?php

$zero_string  = '0';
$zero_int     = 0;
$false        = false;
$empty_string = '';
$array        = array();
$obj          = new stdClass();

echo empty( $zero_string ) ? "'0' = empty\n" : '';
echo empty( $zero_int ) ? "0 = empty\n" : '';
echo empty( $false ) ? "false = empty\n" : '';
echo empty( $empty_string ) ? "'' = empty\n" : '';
echo empty( $array ) ? "array() = empty\n" : '';
echo empty( $obj ) ? "stdClass() = empty\n" : '';
echo empty( $foo ) ? "foo is empty (and the variable was never set)\n" : '';

microformatsDevCamp

Over the weekend, I attended microformatsDevCamp here in San Francisco. It was a chance for a bunch of people who are interested in microformats to get together and hack on some projects that used microformats to Do Cool Things. I ended up being the instigator of one of the projects we worked on, because I had a concrete “system” in mind that would leverage microformats to meet a real need.

The project was to create a web service that would scrape URLs and pull out any content marked up in hCard content (e.g. my contact page) and would then load that content into an LDAP directory. The reason for this is that most Address Book/Contact applications can plug into an LDAP directory to populate their details, so this would provide a direct pipe between client-side contact storage and web-based, decentralized information. The web service would periodically check the URLs it knew about for updates and update LDAP appropriately. If people update their hCard-based information, the LDAP directory would automatically pick up that change and update itself. I’ve talked about this idea before.

Building (or even tinkering with) this system required that we learned about LDAP, and as it turned out, none of us knew much more than the very basic concepts involved with LDAP, so we had a lot of learning to do. I’m putting together a list of LDAP basics that I’ll publish once they’re straightened out a bit. In the meantime, a specifically big thank you to Tantek for organizing ufDevCamp, to Stephen Weber for working with me on the LDAP/code side of things (and showing me how to get started on github.com, and to Mark Ng for setting up an OpenLDAP server for us to play with, and for helping figure out some of the configuration options etc required to get it all working.

Oh, and there’s some code over here if you’re interested, and we made a page on the microformats wiki with some info on our progress.

Simple Activity Streaming with SimplePie

A few different people have asked me recently how I created the activity stream/life stream you see in the sidebar of Dented Reality. It’s actually really simple, and all it does is load up the feeds from a few different locations, combine them in date order and then output them on my page using an HTML “UL” (unordered list). Based on the source of each feed, it also adds a CSS class to each list element (LI) so that I can add an appropriate icon. Here’s the complete code that I use, and then I’ll explain some parts of it, and some of what makes it tick: Read the rest of this post…