/***************
* @function 判断远程图片是否存在
* @Param:
* $url : 地址
* @Return: 返回结果
***************/
function isRealImg($url){
$ch = curl_init();
$timeout = 10;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$contents = curl_exec($ch);
if (preg_match("/404/", $contents)){
return false;
}
return true;
}
/***************
* @function 计算两个时间的差
* @Param:
* $time_1 : 第一个参数
* $time_2 : 第二个参数
* $types : 类型:1--》相差天数,2--》相差小时数,3--》相差分钟数,4--》相差秒数,,默认1;
* @Return: $array 返回结果数组
***************/
function diffTime($time_1,$time_2,$types = 1){
if(!$time_1 || !$time_2){return false;}
if(strtotime(date('Y-m-d H:i:s',$time_1)) != $time_1) {
$time_1 = strtotime($time_1);
}
if(strtotime(date('Y-m-d H:i:s',$time_2)) != $time_2) {
$time_2 = strtotime($time_2);
}
if($time_1 < $time_2){
$temp = $time_1;
$time_1 = $time_2;
$time_2 = $temp;
}
switch ($types) {
case 1:
$diff = (strtotime(date('Y-m-d',$time_1)) - strtotime(date('Y-m-d',$time_2))) / (60*60*24);
break;
case 2:
$diff = (strtotime(date('Y-m-d H',$time_1).':00:00') - strtotime(date('Y-m-d H',$time_2).':00:00')) / (60*60);
break;
case 3:
$diff = (strtotime(date('Y-m-d H:i',$time_1).':00') - strtotime(date('Y-m-d H:i',$time_2).':00')) / 60;
break;
case 4:
$diff = $time_1 - $time_2;
break;
}
return $diff;
}