function
getDistance(
$lat1
,
$lng1
,
$lat2
,
$lng2
)
{
$earthRadius
= 6367000;
$lat1
= (
$lat1
* pi() ) / 180;
$lng1
= (
$lng1
* pi() ) / 180;
$lat2
= (
$lat2
* pi() ) / 180;
$lng2
= (
$lng2
* pi() ) / 180;
$calcLongitude
=
$lng2
-
$lng1
;
$calcLatitude
=
$lat2
-
$lat1
;
$stepOne
= pow(sin(
$calcLatitude
/ 2), 2) +
cos
(
$lat1
) *
cos
(
$lat2
) * pow(sin(
$calcLongitude
/ 2), 2);
$stepTwo
= 2 * asin(min(1, sqrt(
$stepOne
)));
$calculatedDistance
=
$earthRadius
*
$stepTwo
;
return
round
(
$calculatedDistance
);
}
//星期函数 返回当前是今年的第几周 ----->每周天是每周的开始 Ymd return YW
function getWeek($str = ''){
$str = empty($str) ? date('Ymd', time()) : date('Ymd', strtotime($str));
$m = date('Y', strtotime($str));
for($i=1; $i <8; $i++){
if(date('w', strtotime(substr($str,0,4).'01'.sprintf('%02d',$i))) == 0){
$time = strtotime(substr($str,0,4).'01'.sprintf('%02d',$i));break;
}
}
if(!isset($time)) return false;
if((strtotime($str)-$time) > 0)
return $m.sprintf('%02d', intval((strtotime($str)-$time)/60/60/24/7)+1);
elseif((strtotime($str)-$time) == 0)
return $m.'01';
else{
$day = getWeek(date('Y-m-d',strtotime($str)-(7*24*60*60)));
if(substr($day, 4, 2) == '52'){
return ($m-1)."53";
}else{
return ($m-1)."52";
}
}
}
//日期函数 根据星期数返回该星期的日期 周日为每周第一天 || 周一为第一天 YW return 该周开始日期
function weekToDay($str , $type = 0){
$week = substr($str, 4, 2);
if($week < 1 || $week > 54) return false;
$day = ((int)$week-1) * 7;
for($i=1; $i <8; $i++){
if(date('w', strtotime(substr($str,0,4).'01'.sprintf('%02d',$i))) == $type){
$year = substr($str,0,4).'01'.sprintf('%02d',$i);break;
}
}
if(!isset($year)) return false;
return date('Y-m-d', strtotime("+$day day", strtotime($year)));
}