Location: PHPKode > scripts > Time Engine > time-engine/class.worldtimeengine.php
<?php
/**
  * This class can find the geolocation of any given place using yahoo's geolocation service and
  * also the local date and time for that place. This class is very useful for people working with date and
  * time of different places. 
  * 
  * @example 
  * 
  * $wte = new WorldTimeEngine();
  * $geocode = $wte->getGeoCode("Dhaka");
  * $time = $wte->getTime($geocode['lat'],$geocode['lng']);
  * 
  * @author 	Hasin Hayder
  * @since 		March 10th, 2008
  * @copyright 	LGPL
  */

class WorldTimeEngine
{

	/**
	 * This function finds the geocode of any given place using the geocoding service of yahoo
	 * @example getGeoCode("White House, Washington");
	 * @example getGeoCode("Machu Pichu");
	 * @example getGeoCode("Dhaka");
	 * @example getGeoCode("Hollywood");
	 *
	 * @param   string address
	 * @return  array with three key values, lat, lng and address
	 */
	function getGeoCode($address)
	{
		$_url = 'http://api.local.yahoo.com/MapsService/V1/geocode';
		$_url .= sprintf('?appid=%s&location=%s',"phpclasses",rawurlencode($address));
		$_result = false;
		if($_result = file_get_contents($_url)) {
			preg_match('!<Latitude>(.*)</Latitude><Longitude>(.*)</Longitude>!U', $_result, $_match);
			$lng = $_match[2];
			$lat = $_match[1];
			return array("lat"=>$lat,"lng"=>$lng,"address"=>$address);
		}
		else
		return false;
	}

	/**
	 * This function find the local date and time of any place using the geoname web service 
	 *
	 * @example getTime(47.608,-104.231); //time of Machu Pichu
	 * 
	 * @param float $lat
	 * @param float $lng
	 * @return string local date and time in 24 hour format
	 */
	function getTime($lat, $lng)
	{
		$url = "http://ws.geonames.org/timezone?lat={$lat}&lng={$lng}";
		$timedata = file_get_contents($url);
		$sxml = simplexml_load_string($timedata);
		return $sxml->timezone->time;
	}
}
?>
Return current item: Time Engine