note 99410 deleted from datetimezone.listidentifiers by danbrown

From: Date: Tue, 17 Aug 2010 16:39:19 +0000
Subject: note 99410 deleted from datetimezone.listidentifiers by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-171781@lists.php.net to get a copy of this message
Note Submitter: phpnet at netebb dot com ---- chema's version below has missing and mistyped continents. The following code will work well with both PHP 5.2 and PHP 5.3: <?php function getTimeZoneOptions() { $tzids = defined('DateTimeZone::ALL') ? DateTimeZone::listIdentifiers(DateTimeZone::ALL) : DateTimeZone::listIdentifiers(); ksort($tzids); $continent = ''; $rv = ''; foreach ($tzids as $tzid) { if (preg_match( '/^(Africa|America|Antarctica|Arctic|Asia|Atlantic|' . 'Australia|Europe|Indian|Pacific)\/(.*)$/', $tzid, $m)) { if ($m[1] != $continent) { if ($rv) { $rv .= "</optgroup>\n"; } $rv .= sprintf("<optgroup label=\"%s\">\n", htmlspecialchars($m[1])); } $continent = $m[1]; $city = str_replace('_', ' ', $m[2]); $rv .= sprintf("\t<option value=\"%s\">%s</option>\n", htmlspecialchars($tzid), htmlspecialchars($city)); } else { if (defined('DateTimeZone::ALL')) { $tz = str_replace('_', ' ', $tzid); $rv .= sprintf("<optgroup label=\"%s\">\n\t<option value=\"%s\">%s</option>\n</optgroup>\n", htmlspecialchars($tz), htmlspecialchars($tzid), htmlspecialchars($tz)); } } } $rv .= "</optgroup>\n"; return $rv; } ?> <html><body><form><select id="timezone" name="timezone"> <?php echo getTimeZoneOptions(); ?> </select><input type='submit'/></form></body></html>

« previous php.notes (#171781) next »