Day in brief – 2011-08-19

Pukkelpop festival tragedy in Hasselt, Belgium

Associated Press reports:

HASSELT, Belgium (AP) — The death toll from a fierce thunderstorm that mangled tents and downed trees and scaffolding at an open-air music festival in Belgium has risen to five, officials said Friday.

Hasselt Mayor Hilde Claes said that two more people died overnight. About 140 were injured in the storm, 10 of them seriously, she said.

All the dead were Belgians, Claes said.

Organizers canceled the annual Pukkelpop festival near Hasselt, 50 miles (80 kilometers) east of Brussels. Buses and trains were pressed into service to transfer the 60,000 festival goers home.

This is the same Pukkelpop festival that I went to in 2009.  My sincere condolences to the friends and families of the victims.

Day in brief – 2011-08-18

PHP regular expression to match English/Latin characters only

Today at work I came across a task which turned out to be much easier and simpler than I originally thought it would.  We have have a site with some user registration forms.  The site is translated into a number of languages, but due to the regulatory procedures, we have to force users to input their registration details in English only.  Using Latin characters, numbers, and punctuation.

I’ve refreshed my knowledge of Unicode and PCRE.  And then I came up with the following method which seems to do the job just fine.

/**
 * Check that given string only uses Latin characters, digits, and punctuation
 *
 * @param string $string String to validate
 * @return boolean True if Latin only, false otherwise
 */
public function validateLatin($string) {
    $result = false;

    if (preg_match("/^[\w\d\s.,-]*$/", $string)) {
        $result = true;
    }

    return $result;
}

In other words, just a standard regular expression with no Unicode trickery.  The ‘/u’ modifier would cause this to totally malfunction and match everything.  Good to know.