You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
2.9 KiB
122 lines
2.9 KiB
<?php
|
|
|
|
/**
|
|
* 计算指定时间与当前比较剩余多少天
|
|
* @param $time
|
|
*/
|
|
function time_days($time = 0)
|
|
{
|
|
if (!$time || !is_numeric($time)) {
|
|
return ['msg' => '未出租', 'num' => 2];
|
|
}
|
|
|
|
$now_time = time();
|
|
|
|
$days = ceil(($time - $now_time) / 3600 / 24);
|
|
if ($days > 0) {
|
|
return ['msg' => $days . '天后到期', 'num' => 2];
|
|
} else {
|
|
return ['msg' => '已过期' . abs($days) . '天', 'num' => 1];
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 格式化数组,删除字段
|
|
* @param type $_arr 数组对象
|
|
* @param type $field 需要删除的字段
|
|
*/
|
|
function format_field(&$_arr = array(), $_field = array())
|
|
{
|
|
|
|
if (!$_arr || !$_field) {
|
|
return;
|
|
}
|
|
if (!is_array($_field)) {
|
|
$_field = explode(',', $_field);
|
|
}
|
|
$_field = array_flip($_field);
|
|
|
|
array_walk($_arr, function (&$v, &$k) use ($_field) {
|
|
$v = array_intersect_key($v, $_field);
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
*
|
|
* @param type $code 状态编码
|
|
* @param type $data 返回数据
|
|
* @param type $msg 错误的提示信息
|
|
* @return type
|
|
*/
|
|
function send_http_status($code, $_data = array(), $msg = '')
|
|
{
|
|
if (!$code) {
|
|
return;
|
|
}
|
|
$_status = config('status');
|
|
if (isset($_status[$code])) {
|
|
header('HTTP/1.1 200 ' . $_status[$code]);
|
|
// 确保FastCGI模式下正常
|
|
header('Status: 200 ' . $_status[$code]);
|
|
}
|
|
if ($_data == null) {
|
|
$_data = [];
|
|
}
|
|
$msg = empty($msg) ? $_status[$code] : $msg;
|
|
$_msg = [
|
|
'code' => $code,
|
|
'msg' => $msg,
|
|
'data' => $_data,
|
|
'time' => $_SERVER['REQUEST_TIME'],
|
|
];
|
|
return json_encode($_msg, JSON_UNESCAPED_UNICODE);
|
|
}
|
|
|
|
|
|
/**
|
|
* 去除html js css 危险注入代码
|
|
*/
|
|
function filter_danger_str($_string)
|
|
{
|
|
$search = array("'<script[^>]*?>.*?</script>'si", // 去掉 javascript
|
|
"'<style[^>]*?>.*?</style>'si", // 去掉 css
|
|
"'<[/!]*?[^<>]*?>'si", // 去掉 HTML 标记
|
|
"'<!--[/!]*?[^<>]*?>'si", // 去掉 注释标记
|
|
"'([rn])[s]+'", // 去掉空白字符
|
|
"'&(quot|#34);'i", // 替换 HTML 实体
|
|
"'&(amp|#38);'i",
|
|
"'&(lt|#60);'i",
|
|
"'&(gt|#62);'i",
|
|
"'&(nbsp|#160);'i",
|
|
"'&(iexcl|#161);'i",
|
|
"'&(cent|#162);'i",
|
|
"'&(pound|#163);'i",
|
|
"'&(copy|#169);'i",
|
|
);
|
|
$replace = array("", "", "", "", "\1", "\"", "&", "<", ">", " ", chr(161), chr(162), chr(163), chr(169));
|
|
|
|
$out = preg_replace($search, $replace, $_string);
|
|
return htmlspecialchars_custom($out);
|
|
}
|
|
|
|
//过滤单双引号
|
|
function htmlspecialchars_custom($str)
|
|
{
|
|
return htmlspecialchars($str, ENT_QUOTES);
|
|
}
|
|
|
|
function order_no(){
|
|
return date('Ymd').rand(1000,9999).date('His').rand(1000,9999);
|
|
}
|
|
|
|
function formart_time($time){
|
|
if ($time < strtotime(date("Y-m-d",strtotime('+1 day'))) ){
|
|
return '今天';
|
|
}elseif ( $time < strtotime(date("Y-m-d",strtotime('+2 day'))) ){
|
|
return '明天';
|
|
}else{
|
|
return date('Y-m-d',$time);
|
|
}
|
|
}
|