note 99410 added to datetimezone.listidentifiers

From: Date: Mon, 16 Aug 2010 08:22:59 +0000
Subject: note 99410 added to datetimezone.listidentifiers
Groups: php.notes 
Request: Send a blank email to php-notes+get-171724@lists.php.net to get a copy of this message
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> ---- Server IP: 69.147.83.197 Probable Submitter: 122.169.88.143 ---- Manual Page -- http://www.php.net/manual/en/datetimezone.listidentifiers.php Edit -- https://master.php.net/note/edit/99410 Del: integrated -- https://master.php.net/note/delete/99410/integrated Del: useless -- https://master.php.net/note/delete/99410/useless Del: bad code -- https://master.php.net/note/delete/99410/bad+code Del: spam -- https://master.php.net/note/delete/99410/spam Del: non-english -- https://master.php.net/note/delete/99410/non-english Del: in docs -- https://master.php.net/note/delete/99410/in+docs Del: other reasons-- https://master.php.net/note/delete/99410 Reject -- https://master.php.net/note/reject/99410 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#171724) next »