function getcityfromip($ip)
{
$arr = json_decode(@file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip=' . $ip), true);
if ($arr['code'] == 0) {
return $arr['data']['city'];
}
}
function getlatfromcity($city)
{
$url =
$arr = json_decode(@file_get_contents('http://api.map.baidu.com/geocoder/v2/?address=' . $city . '&output=json&ak=81UhB6XjIeFA6HLvLVSavOvPyp0ZEzgD'), true);
if ($arr['status'] == 0) {
return $arr['result']['location'];
}
}
function getLocation($ip)
{
$url = 'http://api.map.baidu.com/location/ip?';
$option = array(
'ip' => $ip,
'ak' => '81UhB6XjIeFA6HLvLVSavOvPyp0ZEzgD',
);
$url .= http_build_query($option);
$data = file_get_contents($url);
$data = json_decode($data, true);
return $data['content']['point'];
}
ak无效,需要更换1.获取最近本月的每周区间
function get_weekinfo($month)
{
$weekinfo = array();
$end_date = date('d', strtotime($month . ' +1 month -1 day'));
for ($i = 1; $i < $end_date; $i = $i + 7) {
$w = date('N', strtotime($month . '-' . $i));
$weekinfo[] = array(date('Y-m-d', strtotime($month . '-' . $i . ' -' . ($w - 1) . ' days')), date('Y-m-d', strtotime($month . '-' . $i . ' +' . (7 - $w) . ' days')));
}
return $weekinfo;
}2.获取本周的开始和结束日期
function getfirstendday()
{
$date = new DateTime();
$date->modify('this week');
$arr['start'] = $date->format('m-d');
$date->modify('this week +6 days');
$arr['end'] = $date->format('m-d');
return $arr;
}本文为看恩吧原创文章,转载无需和我联系,但请注明来自knsay.com