php get_timezone_byt_lat_long_inkplant.com.php

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php get_timezone_byt_lat_long_inkplant.com.php相关的知识,希望对你有一定的参考价值。

// https://inkplant.com/code/get-timezone
<?php

function get_timezone($latitude,$longitude,$username) {

	//error checking
	if (!is_numeric($latitude)) { custom_die('A numeric latitude is required.'); }
	if (!is_numeric($longitude)) { custom_die('A numeric longitude is required.'); }
	if (!$username) { custom_die('A GeoNames user account is required. You can get one here: http://www.geonames.org/login'); }

	//connect to web service
	$url = 'http://ws.geonames.org/timezone?lat='.$latitude.'&lng='.$longitude.'&style=full&username='.urlencode($username);
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$xml = curl_exec($ch);
	curl_close($ch);
	if (!$xml) { $GLOBALS['error'] = 'The GeoNames service did not return any data: '.$url; return false; }

	//parse XML response
	$data = new SimpleXMLElement($xml);
	//echo '<pre>'.print_r($data,true).'</pre>'; die();
	$timezone = trim(strip_tags($data->timezone->timezoneId));
	if ($timezone) { return $timezone; }
	else { $GLOBALS['error'] = 'The GeoNames service did not return a time zone: '.$url; return false; }

}

?>

以上是关于php get_timezone_byt_lat_long_inkplant.com.php的主要内容,如果未能解决你的问题,请参考以下文章

php PHP__YII__controller

php PHP __ $ _ SESSION - $ _ COKKIE

php php__newline.php

require(dirname(__FILE__).'/'.'myParent.php') 比 require('myParent.php') 有啥好处?

php PHP __ $ _ POST / $ _GET / $ _REQUEST

PHP的 __DIR__ 作用