note 57022 added to function.putenv

From: Date: Wed, 21 Sep 2005 20:02:03 +0000
Subject: note 57022 added to function.putenv
Groups: php.notes 
Request: Send a blank email to php-notes+get-95559@lists.php.net to get a copy of this message
Okay, so here's the format that TZ is looking for "America/New_York". You can get all of the timezones from a single file on most unix systems. This code works on all Linux systems that I have seen (various redhat/deb) where you can find this file... And now you have a nice, one level nested timezone list by country. <?php // -- first part, gather all of the zone data $zoneSource = '/usr/share/zoneinfo/zone.tab'; $zoneHandle = fopen($zoneSource, "r"); if (!$zoneHandle) return NULL; //bad file, abort now while (!feof($zoneHandle)) { $zoneLine = ltrim(fgets($zoneHandle, 4096)); if ($zoneLine[0]=='#') continue; //skip comments //Columns... // 1. ISO 3166 2-character country code. // 2. Latitude and longitude of the zone's principal location // 3. Zone name used in value of TZ environment variable. // 4. Comments; present if and only if country has multiple rows. $zoneParts = explode("\t",$zoneLine); //grab parts if (count($zoneParts) < 3) continue; //erroneous line! $nameParts = explode('/', $zoneParts[2], 2); //grab country/name $zoneKey = $nameParts[0]; //country or area $insertArray = &$zoneNames; //where to insert? if (count($nameParts) > 1) { //area/populous if (!isset($zoneNames[$zoneKey])) //not set before $zoneNames[$zoneKey] = array(); $insertArray = &$zoneNames[$zoneKey]; //grab sub (country) $zoneKey = trim($nameParts[1]); //grab correct key } $zoneKey = preg_replace('/[_]/',' ', $zoneKey); $insertArray[$zoneKey] = trim($zoneParts[2]); //actually set data } //end while not eof fclose($zoneHandle); ?> ---- Manual Page -- http://www.php.net/manual/en/function.putenv.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57022 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57022&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57022&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57022&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57022&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57022&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57022&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57022&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57022&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#95559) next »