ip.php 获取经纬度,【php函数】根据ip获取位置和城市,经纬度

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 

$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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值