/**
* 获取指定日期段内每一天的日期
* @param Date $startdate 开始日期
* @param Date $enddate 结束日期
* @return Array
*/
function getDateFromRange($startdate, $enddate){
$stimestamp = strtotime($startdate);
$etimestamp = strtotime($enddate);
// 计算日期段内有多少天
$days = ($etimestamp-$stimestamp)/86400+1;
// 保存每天日期
$date = array();
for($i=0; $i<$days; $i++){
$date[] = date('Y-m-d', $stimestamp+(86400*$i));
}
return $date;
}
/**
* 计算两点地理坐标之间的距离
* @param Decimal $longitude1 起点经度
* @param Decimal $latitude1 起点纬度
* @param Decimal $longitude2 终点经度
* @param Decimal $latitude2 终点纬度
* @param Int $unit 单位 1:米 2:公里
* @param Int $decimal 精度 保留小数位数
* @return Decimal
*/
function getDistance($longitude1, $latitude1, $longitude2, $latitude2, $unit=2, $decimal=2){
$EARTH_RADIUS = 6370.996; // 地球半径系数
$PI = 3.1415926;
$radLat1 = $latitude1 * $PI / 180.0;
$radLat2 = $latitude2 * $PI / 180.0;
$radLng1 = $longitude1 * $PI / 180.0;
$radLng2 = $longitude2 * $PI /180.0;
$a = $radLat1 - $radLat2;
$b = $radLng1 - $radLng2;
$distance = 2 * asin(sqrt(pow(sin($a/2),2) + cos($radLat1) * cos($radLat2) * pow(sin($b/2),2)));
$distance = $distance * $EARTH_RADIUS * 1000;
if($unit==2){
$distance = $distance / 1000;
}
return round($distance, $decimal);
}
/** 图片局部打马赛克
* @param String $source 原图
* @param Stirng $dest 生成的图片
* @param int $x1 起点横坐标
* @param int $y1 起点纵坐标
* @param int $x2 终点横坐标
* @param int $y2 终点纵坐标
* @param int $deep 深度,数字越大越模糊
* @return boolean
*/
function imageMosaics($source, $dest, $x1, $y1, $x2, $y2, $deep){
// 判断原图是否存在
if(!file_exists($source)){
return false;
}
// 获取原图信息
list($owidth, $oheight, $otype) = getimagesize($source);
// 判断区域是否超出图片
if($x1>$owidth || $x1<0 || $x2>$owidth || $x2<0 || $y1>$oheight || $y1<0 || $y2>$oheight || $y2<0){
return false;
}
switch($otype){
case 1: $source_img = imagecreatefromgif($source); break;
case 2: $source_img = imagecreatefromjpeg($source); break;
case 3: $source_img = imagecreatefrompng($source); break;
default:
return false;
}
// 打马赛克
for($x=$x1; $x<$x2; $x=$x+$deep){
for($y=$y1; $y<$y2; $y=$y+$deep){
$color = imagecolorat($source_img, $x+round($deep/2), $y+round($deep/2));
imagefilledrectangle($source_img, $x, $y, $x+$deep, $y+$deep, $color);
}
}
// 生成图片
switch($otype){
case 1: imagegif($source_img, $dest); break;
case 2: imagejpeg($source_img, $dest); break;
case 3: imagepng($source_img, $dest); break;
}
return is_file($dest)? true : false;
}
$source = 'source.jpg';
$dest = 'dest.jpg';
$flag = imageMosaics($source, $dest, 176, 98, 273, 197, 7);
echo '<img src="'.$source.'">';
echo '<img src="'.$dest.'">';
/**
* 二代身份证校验
* @param 六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码
* @return [type] [description]
*/
function checkIdCard($idcard){
// 只能是18位
if(strlen($idcard)!=18){
return false;
}
// 取出本体码
$idcard_base = substr($idcard, 0, 17);
// 取出校验码
$verify_code = substr($idcard, 17, 1);
// 加权因子
$factor = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
// 校验码对应值
$verify_code_list = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
// 根据前17位计算校验码
$total = 0;
for($i=0; $i<17; $i++){
$total += substr($idcard_base, $i, 1)*$factor[$i];
}
// 取模
$mod = $total % 11;
// 比较校验码
if($verify_code == $verify_code_list[$mod]){
return true;
}else{
return false;
}
}