Archive for March, 2007

Array sorting but without articles

Saturday, March 31st, 2007

Sometimes you want to sort an array in PHP, but exclude certain words.
I once needed this to sort a list of artists and bands. It is very common for bandnames to have articles in front of them.
When sorting those, it feels more natural to leave those words out, so that “The Doors” would end up at the letter D, and not T.
This little PHP function will do natcasesort, but will leave out the english articles a, an, the, and the dutch articles de, het and een:

function sort_na($a, $prefix= '/^((d|th)e|an?|een|het)s*/i') {
    $n=0;
    foreach($a as $entry){
        $b[$n]['name']=preg_replace($prefix,"",$entry);
        $b[$n]['name_no_prefix']=$entry;
        $n++;
    }
    $cmp=create_function('$x, $y',
        'return strnatcasecmp($x["name"], $y["name"]);');
    usort($b, $cmp);
    $n=0;
    foreach($b as $entry) {
        $c[$n]=$entry['name_no_prefix'];
        $n++;
    }
    return $c;
}

Workaround for “empty-contact-list” problem in Nokia PC Suite

Tuesday, March 27th, 2007

I recently lost my good-old Nokia 6100 mobile phone. Luckily, my provider KPN gave me a new one for free, a Nokia 5500 Sport. After a few weeks I found my old phone and was very happy that I had my 150+ contacts back :)

The Nokia PC Suite software made it look like I could simply copy all the contacts, but unfortunately the Contact List for the 6100 model in my Nokia Phone Browser always shows up empty :(

However, I was able to make a Full Backup using the application. That yielded a .nbu file, which upon inspection held the contact details in VCARD format, but smeared together with lots of binary poop.

I created a webpage that will parse an .nbu file, and give back a zipped VCARD file containing all your contacts. You can then simply drag this into the Contact List of your new phone.

I have used this to export 219 contacts from my Nokia 5500 to an HTC Hero.
You need to install vCardIO, then simply copy the contacts.vcf into the root of the SD card and import all of them.

TODO: I need to add a X-IRMC-LUID property to avoid multiple additions…